JavaScript Math.random()
Examples
Return a random number between 0 (inclusive) and 10 (exclusive):
Return a random number between 0 (inclusive) and 100 (exclusive):
A random whole number between 1 and 10 (inclusive):
A random whole number between 1 and 100 (inclusive):
Description
TheMath.random() method returns a random floating point number between 0 (inclusive)and 1 (exclusive).
Note
Math.random() does not return a cryptographically secure number.
If you need a cryptographically secure number, use this Crypto API method:
crypto.getRandomValues()
Syntax
Parameters
| NONE |
Return Value
| Type | Description |
| Number | A random number from 0 (inclusive) up to but not including 1 (exclusive). |
Browser Support
Math.random() is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera |

