What is the lowest number and what is the highest number generated by Math.random()?
September 25, 2012 2:41 PM   Subscribe

JavaScript question: What is the lowest number and what is the highest number generated by Math.random()?— 0.0000000000000000 or 0.0000000000000001, 1.0000000000000000 or 0.9999999999999999
posted by markcmyers to Technology (3 answers total) 1 user marked this as a favorite
 
Best answer: One of the first results I found for "javascript math.random" was from the Mozilla documentation:

Returns a floating-point, pseudo-random number in the range [0, 1) that is, from 0 (inclusive) up to but not including 1 (exclusive).
posted by Tomorrowful at 2:45 PM on September 25, 2012


Best answer: Mozilla Developer Network:
Returns a floating-point, pseudo-random number in the range [0, 1) that is, from 0 (inclusive) up to but not including 1 (exclusive), which you can then scale to your desired range.

Note that as numbers in JavaScript are IEEE 754 floating point numbers with round-to-nearest-even behavior, these ranges, excluding the one for Math.random() itself, aren't exact, and depending on the bounds it's possible in extremely rare cases (on the order of 1 in 262) to calculate the usually-excluded upper bound.
posted by Foci for Analysis at 2:45 PM on September 25, 2012


That's 1 in 262, not 1 in 262.
posted by flabdablet at 6:27 PM on September 25, 2012


« Older How to protest closing of a park?   |   NC personal injury lawyer? Newer »
This thread is closed to new comments.