Random Number Generator

Pick a random whole number between two bounds

Random Number Generator

Random number from
to

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

N = max − min + 1

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

1 − (1 − 1/N)k

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

  1. The browser fills a 32-bit word from crypto.getRandomValues() — a value from 0 to 4,294,967,295.
  2. Words at or above ⌊232 / N⌋ × N are 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.
  3. 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

RangeWhole numbersChance of each number Draws to reach 50%
1–2250%1
1–66≈16.67%4
1–101010%7
1–20205%14
1–1001001%69
1–1,0001,0000.1%693
1–10,00010,0000.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

Random Number Generator

This generator picks a random whole number between two bounds, both of them included. The number is drawn in your browser from its cryptographic random source, and every number in the range has the same chance. For example, it can help you find out random number between 1 and 100? Enter the lower bound (e.g. '1') and the upper bound (e.g. '100'), then press 'Generate'. On the result page you can draw several numbers at once, with or without repeats.

FAQ

How does the random number generator pick a number?

It asks your browser for a 32-bit random value from crypto.getRandomValues() and maps it onto the range. Values from the incomplete last block of the 32-bit space are thrown away and drawn again (rejection sampling), so every number in the range gets exactly the same chance instead of the small numbers being slightly favoured.

Are both bounds included?

Yes. A range from 1 to 100 holds 100 whole numbers, and 1 and 100 come up as often as 50 does. In general the range from min to max holds max − min + 1 numbers, each with a chance of 1 in that count.

Can I draw several numbers without repeats?

Yes. Set how many numbers you need and tick «No repeats»: the generator then draws without replacement, like taking balls out of a drum, so no number appears twice. Without repeats you cannot ask for more numbers than the range holds.

Is the number truly random?

The browser's cryptographic generator is seeded from the operating system's entropy and is designed so that its output cannot be predicted — the same kind of source that produces encryption keys. It is still an algorithm, not a physical process; for an officially witnessed draw use the procedure your rules require.