Javascript's MATH object has a random method that returns from the set [0,1) 0 inclusive, 1 exclusive. Is there a way to return a truly random method that includes 1.
e.g.
var rand = MATH.random()*2; if(rand > 1) { rand = MATH.floor(rand); } return rand;
While this always returns a number from the set [0,1] it is not truly random.
This will return [0,1] inclusive:
if(MATH.random() == 0) return 1; else return MATH.random();
Explanation: If the first call to random() returns 0, return 1. Otherwise, call random again, which will be [0,1). Therefore, it will return [0,1] all inclusive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With