This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

random

Summary

Returns a pseudorandom number between 0 and 1.

Syntax

Math.random( )

Examples

Math.random(); // 0.6236026335973293
Math.random(); // 0.10149288410320878
Math.random(); // 0.6313296002335846

Remarks

The pseudo-random number generated is from 0 (inclusive) to 1 (exclusive), that is, the returned number can be zero, but it will always be less than one. The random number generator is seeded automatically when JavaScript is first loaded.

Due to the nature of the generation methods, these pseudo-random numbers are not uniformly distributed. They are normally distributed which means that, in general, a number is more likely to be closer to 0.5 than 0 or 1.

Note that this method is unsuitable for cryptography. The WebCrypto API addresses this.

See also

Other articles

Attributions