Ad Space — Top Banner

Random Number Generator

Generate random integers or decimals within any custom range.
Set min, max, count, and decimal places for lottery picks, dice rolls, raffles, and sampling.

Generated Numbers

Random number generation uses algorithms to produce values that appear statistically unpredictable within a defined range. Understanding the underlying math helps you use random numbers correctly in games, decisions, sampling, and simulations.

Core formula (integer generation): Random Integer = Math.floor(Math.random() × (max − min + 1)) + min

Where:

  • Math.random() generates a pseudo-random float ≥ 0 and < 1
  • (max − min + 1) scales the range to include both endpoints
  • Math.floor() converts the float to a whole number
  • + min shifts the result to your desired starting value

Probability of any single value: P(x) = 1 ÷ (max − min + 1)

For a 1–100 range: P(any number) = 1/100 = 1% per value

Common use cases and their settings:

Use Case Min Max Notes
Coin flip 0 1 0 = tails, 1 = heads
Standard die 1 6 Each face ~16.67%
D20 (tabletop RPG) 1 20 Each value 5% probability
Lottery draw (6 of 49) 1 49 Run 6 times, no repeats
Random team picker 1 N N = number of teams

Expected value (multiple rolls): For a fair die (1–6), the expected value = (1+2+3+4+5+6)/6 = 3.5 For a 1–100 range, expected average = 50.5

Worked example — selecting a random winner from 80 entrants: min = 1, max = 80 Each entrant has a 1/80 = 1.25% chance of winning. Generate one number from 1–80; the person assigned that number wins.

Important limitation: Math.random() is a pseudo-random generator seeded by system state. It is entirely adequate for games, simulations, and everyday decisions, but cryptographically insecure. For security-sensitive applications (passwords, cryptography), use crypto.getRandomValues() instead.


Ad Space — Bottom Banner

Embed This Calculator

Copy the code below and paste it into your website or blog.
The calculator will work directly on your page.