Skip to main content
Version: 3.13.0

Math.random()

The Math.random() function returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range — which you can then scale to your desired range. The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or reset by the user.

Note: Math.random() does not provide cryptographically secure random numbers. Do not use them for anything related to security. Use the Web Crypto API instead, and more precisely the crypto.getRandomValues() method.

Syntax

Math.random()

Return value

A floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive).