Random Number Generator
Pick a random whole number between two bounds
Random Number Generator
How the Random Number Generator Works
Popular ranges
1–10 · 1–100 · 1–6 · 1–2 · 1–3 · 1–4 · 1–5 · 1–20 · 1–50 · 1–1,000 · 0–9 · 0–1 · 1–60 · 1–12 · 1–30 · 1–8 · 1–25 · 1–365 · 1–10,000 · 0–100 · 1–200 · 1–500 · 1–40 · 0–10
The formula behind every range
A range from min to max with both ends included holds
whole numbers, and a fair generator gives each of them the same chance, P = 1 / N. The «+ 1» is the part people forget: from 1 to 100 there are 100 numbers, not 99, because the fence-post at either end counts too. With repeats allowed the draws are independent, so the chance that a particular number shows up at least once in k draws is
and it passes 50% after about 0.69 × N draws (ln 2 ≈ 0.693), not after N / 2.
How a number is drawn, step by step
- The browser fills a 32-bit word from
crypto.getRandomValues()— a value from 0 to 4,294,967,295. - Words at or above
⌊232 / N⌋ × Nare thrown away and drawn again. That cut makes the space an exact multiple of N; without it the remainder would slightly favour the low numbers. - The kept word is divided by N, and the remainder is added to min. For several different numbers the generator shuffles the range partially (Fisher–Yates), so each number can come out only once.
Why not Math.random()
Math.random() is a fast general-purpose generator: the language standard does not require it to be unpredictable, and browsers implement it with algorithms whose next output can be reconstructed from earlier ones. crypto.getRandomValues() is the browser's cryptographically secure source, seeded from the operating system — the one used for encryption keys. There is no fallback: a browser without it gets a message, not a weaker number.
Reading the result
| Range | Whole numbers | Chance of each number | Draws to reach 50% |
|---|---|---|---|
| 1–2 | 2 | 50% | 1 |
| 1–6 | 6 | ≈16.67% | 4 |
| 1–10 | 10 | 10% | 7 |
| 1–20 | 20 | 5% | 14 |
| 1–100 | 100 | 1% | 69 |
| 1–1,000 | 1,000 | 0.1% | 693 |
| 1–10,000 | 10,000 | 0.01% | 6,932 |
«Draws to reach 50%» is how many independent draws give one particular number an even chance of having appeared at least once. Past draws change nothing: a number that has not come up for a while is not «due».
What people use it for
- Giveaways and raffles: number the entries and draw a winner from 1 to the number of entries.
- Lottery-style picks: several different numbers at once with «No repeats», sorted if you like.
- Games: a stand-in for dice — 1 to 6 for a regular die, 1 to 20 for a d20.
- Classrooms and meetings: pick whose turn it is from a numbered list.
- Sampling: choose which rows, items or respondents go into a random sample.
- Settling a choice: when every option is equally fine, let a number decide.
Limits and caveats
- An algorithm, not a physical process. The numbers come from a cryptographically secure pseudo-random generator: unpredictable in practice, but computed. Services such as random.org take their randomness from physical noise instead; for most everyday draws the difference cannot be observed.
- Whole numbers only, from 0 to 1,000,000; the lower bound must be smaller than the upper one.
- Up to 1,000 numbers per draw, and without repeats no more than the range holds.
- Nothing is recorded. The history lives only in this tab; for a draw that must be witnessed or audited, follow the procedure your rules prescribe.
See Also
- Spin the Wheel - Random name picker and decision wheel — spin it and it chooses for you
- Percent to Probability Converter - Convert Percents to "1 in X" Probability Chance