Math.random() (Function)

Generate a pseudo-random value.


ECMAScript edition - 2
JavaScript - 1.1
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.02
Netscape Enterprise Server version - 2.0
Opera - 3.0
Property/method value type:Number primitive
JavaScript syntax:-Math.random()

The Math.random() function generates and returns a pseudo-random value; a positive value between 0 and 1.

The resulting value is chosen randomly (or pseudo randomly) depending on the implementation.

In any case, regardless of how it is selected, it should yield a uniform distribution over the range of possible values.

The exact value yielded by this function may vary slightly from implementation to implementation due to differences in the underlying precision of the implementations math routines, and the specific algorithm selected to generate the random numbers.

Some implementations may provide a way to seed the random number sequence although the ECMAScript standard does not describe this capability.

Some implementations provide predictable series of random numbers that always start at the same seed point.

The algorithm and strategy is implementation dependant and the standard offers no recommendations as to which is best.


See also:Math object, Pseudo-random numbers


ECMA 262 edition 2 - section -

ECMA 262 edition 3 - section -

Bibliographic reference: