Forum Moderators: open

Message Too Old, No Replies

Math.random() function?

         

TomJS

1:42 pm on Jan 23, 2004 (gmt 0)

10+ Year Member



Hi guys, I was just wondering if you do a math.random number from 0 to 1, is it possible to get 0 or 1, or are they not included?

DrDoc

4:28 pm on Jan 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World!

Well, it entirely depends on the way you use the random number generator.
Math.floor(Math.random()*2) will always return a value that is either 0 or 1.
Other than that, I think 0 and 1 should be included in a regular Math.random()... But I'm not sure. It's not very likely to ever appear anyway :)

TomJS

9:29 pm on Jan 23, 2004 (gmt 0)

10+ Year Member



I know that if you floor/rond it blah blah blah what I want to know is if it is possible to get a 0 or a 1 if u just put math.random? I know it is EXTREMELY unlikely but it could be possible, does anybody know?

dcrombie

1:26 pm on Jan 24, 2004 (gmt 0)



I think the range for Math.random() is [0,1) but the documentation I've read isn't clear on that.