PDA

View Full Version : Math.random()



danhodkinson
March 20th, 2008, 06:01 PM
does math.random return a 0 or a 1, or does it return 0,0.1,0.2...1?
just curious as im using a code with (math.random()*10)+5;
but if it only returns a 0 or a 1 its not that random as it will either be 5 or 15,
just wondering is all!
thanks

Krilnon
March 20th, 2008, 06:09 PM
Isn't this easy enough to test yourself?
for(var i:int = 0; i < 100; i++){
trace(Math.random());
}


Returns a pseudo-random number n, where 0 <= n < 1. The number returned is calculated in an undisclosed manner, and pseudo-random because the calculation inevitably contains some element of non-randomness.

danhodkinson
March 20th, 2008, 06:11 PM
i realised that about 20 seconds after i posted it! nice to see people still help out with the easy problems.