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
- useId — The React hook that generates a unique ID string that is stable across renders and matches between server and browser.
- hydration — The step where React in the browser attaches event handlers and state to HTML that was already rendered on the server.
- pure function — A function whose result depends only on its arguments and which has no side effects, so the same inputs always give the same output.
Taught in
- useId: Generating Stable Accessible Form Element Identifiers — React 19 & Modern Component Architecture