Join 3,365 readers in helping fund MetaFilter (Hide)


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
 
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


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 Is there anything I can do abo...   |  Can anyone recommend a good pe... Newer »
This thread is closed to new comments.