JavaScript Math.random() Method
The Math.random() static method returns a pseudo-random decimal number from 0 up to (but not including) 1. Scale and round it to get random integers.
Description
The Math.random() static method returns a pseudo-random floating point number in the range 0 to less than 1, with roughly even distribution. To get a random integer between min and max inclusive, use Math.floor(Math.random() * (max - min + 1)) + min. To pick a random array element, use arr[Math.floor(Math.random() * arr.length)].
It's not suitable for anything security-related, such as passwords or tokens, because its output can be predicted. Use crypto.getRandomValues() or crypto.randomUUID() instead.
Each call returns a new, independent number, and there's no way to set a seed to get the same sequence again; for reproducible random numbers, such as in tests or procedural generation, use a small seeded generator function instead.
Syntax
Math.random()Return Value
A pseudo-random number from 0 (inclusive) up to but not including 1.
Example
Browser Support
The following information will show you the current browser support for the Math.random() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





