JS Built-ins
← Math175 / 215
Mathrandomintermediate

Math.random() β€” Dice Roll 0-5

πŸ“– Usage Example
// Pseudo-random float in [0, 1)
Math.random()                        // β†’ e.g. 0.7421...
Math.floor(Math.random() * 6)        // β†’ 0–5

Use Math.random() to generate a pseudo-random floating-point number between 0 (inclusive) and 1 (exclusive).

Math.random()

Returns a pseudo-random floating-point number in the range [0, 1).

Challenge: Use Math.floor(Math.random() * 6) to simulate a die roll producing integers 0–5.

πŸ’‘ Hints (1)
  • β€’ Math.floor(Math.random() * N) produces integers from 0 to N-1