Understanding the random number generator — concept and principle
This tool draws random numbers within a range you choose, with or without repeats, as whole numbers or decimals, sorted or in draw order. It also shows the count, sum, average, the number of possible values and the number of possible different sets. Use it for classroom draws, picking winners, games, sampling and practice lottery-style draws.
How it is calculated
- Numbers come from the browser's cryptographic random generator (crypto.getRandomValues).
- Each value is a uniform whole number in the range; for decimals the range is scaled first.
- Rejection sampling removes the small bias a simple remainder operation would cause.
- Without repeats, the draw is a partial Fisher–Yates shuffle, so every set is equally likely.
- Possible sets without repeats = C(N, k) = N! ÷ (k!(N − k)!), with N values in the range and k numbers drawn.
Changing any input, including "Draw number", produces a new draw.
The principle
A fair draw needs every allowed value (or set) to be equally likely. Computers produce random bits; turning them into a number in a range by taking a remainder slightly favours small values unless the range divides the number of bit patterns evenly. Rejection sampling fixes this by discarding the few raw values that would cause bias and drawing again. The Fisher–Yates shuffle draws without repeats by swapping each chosen value out of the remaining pool, which gives every ordering the same chance.
Worked example
Default inputs: 1 to 45, 6 numbers, no repeats, whole numbers, sorted. The draw shown on the page was:
- Numbers: 3, 20, 22, 23, 31, 42.
- Count 6; sum 3 + 20 + 22 + 23 + 31 + 42 = 141.
- Average 141 ÷ 6 = 23.5.
- Values possible in the range: 45.
- Possible different sets: C(45, 6) = 8,145,060.
Your own draw will show different numbers; the last two figures stay the same.
How to read the result
Each set of 6 from 45 has the same chance, 1 in 8,145,060. Sets that look patterned, like 1, 2, 3, 4, 5, 6, are exactly as likely as any other. The average of a fair draw tends toward the middle of the range (23 here) over many draws, but any single draw can differ widely.
Common mistakes
- Believing some numbers are "due" after not appearing; each draw is independent.
- Allowing repeats when the use case needs distinct numbers, or the reverse.
- Expecting the draw to change without changing an input.
- Treating the sum or average as meaningful for a single draw.
Frequently asked questions
Is this truly random?
It uses the browser's cryptographic generator, which is designed to be unpredictable; that is suitable for everyday draws.
How do I draw again with the same settings?
Change the "Draw number" field; each new value triggers a new draw.
What are the odds of matching all 6 numbers from 45?
1 in 8,145,060 for a fair draw.
Sources: W3C Web Cryptography API, crypto.getRandomValues · D. E. Knuth, The Art of Computer Programming, Vol. 2, §3.4.2 (random sampling and shuffling)