Javascript Reference
Categories: Math

javascript Math random( )

@March 15, 2008, 1:22 a.m.
random( )Firefox/Netscape/NN 2 IE 3 ECMA 1  

  

Returns a pseudo-random number between 0 and 1. To calculate a pseudo-random integer between zero and another maximum value, use the formula:

Math.floor(Math.random( ) * (n+1))

where n is the top integer of the acceptable range. To calculate a pseudo-random integer between a range starting with a number other than zero, use the formula:

Math.floor(Math.random( ) * n - m + 1) + m

where m is the lowest integer of the acceptable range and n equals the maximum value of the range. Note that the Math.random( ) method does not work in the Windows and Macintosh versions of Navigator 2.

 
Parameters

None.

 
Returned Value

Number from 0 up to, but not including, 1.


Powered by Linode.