On this page
  1. Math.random
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

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

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