On this page
Math.random
Prev: min | Up: Math | Next: hypot
Rel: Math, JSON, Math, BigInt & Date Guide
Ref: MDN Web Docs — Math.random
Tags: #public #web #javascript #builtins #math #tier/core
Signature & Overview
Math.random()
Returns a pseudo-random floating-point number in [0, 1).
Notes & Pitfalls
- NOT cryptographically secure: Never use for tokens, session IDs, or passwords—use
crypto.getRandomValues()orcrypto.randomUUID()instead.
Example
const randInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
const roll = randInt(1, 6);
console.assert(roll >= 1 && roll <= 6);
Linked from
Related notes
- tuts/javascript/builtins/Math/hypot Linked here; links to this page; shared tags: #builtins, #javascript, #math, #tier, #web
- tuts/javascript/builtins/Math/min Linked here; links to this page; shared tags: #builtins, #javascript, #math, #tier, #web
- tuts/javascript/builtins/Math Linked here; links to this page; shared tags: #builtins, #javascript, #math, #web
- tuts/javascript/builtins/json_math_and_date Linked here; shared tags: #builtins, #javascript, #web
- tuts/javascript/builtins/Math/floor shared tags: #builtins, #javascript, #math, #tier, #web
- tuts/javascript/builtins/Array/at shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/filter shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/find shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/flatMap shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/from shared tags: #builtins, #javascript, #tier, #web