Math.random

The JavaScript function that returns a pseudo-random number between 0 and 1.

In more detail

Its output is not predictable, so code that calls it gives different results on every run. It is not suitable for anything security-related; use crypto.getRandomValues instead.

Example

Calling it during a React render makes the component impure and, with server rendering, causes hydration mismatches.

Related terms

Taught in

References