Random Number
generator.
Draw one number or thousands from any range, each value equally likely.
68 is one of 100 equally likely whole numbers, so it had a 1 in 100 chance (1%). The next draw does not remember it: 68 is just as likely to come up again.
How the draws spread
- Draws
- Expected
- 95% band
- Outside the band
1,000 independent test draws from 1 to 100 in 20 bars of 5 values each. Each bar expects 50, and 95% of bars should land between 36.5 and 63.5. 1 of 20 bars falls outside that band. Counts: 1 to 5: 54; 6 to 10: 44; 11 to 15: 45; 16 to 20: 52; 21 to 25: 45; 26 to 30: 43; 31 to 35: 56; 36 to 40: 61; 41 to 45: 48; 46 to 50: 53; 51 to 55: 44; 56 to 60: 53; 61 to 65: 48; 66 to 70: 44; 71 to 75: 37; 76 to 80: 48; 81 to 85: 68; 86 to 90: 60; 91 to 95: 51; 96 to 100: 46.
- Chi-square
- 20.48
- Degrees of freedom
- 19
- p-value
- 0.366
- At the 5% level
- Nothing unusual
Pearson's chi-square test adds (count − expected)² ÷ expected over the bars. A p-value under 0.05 fails the 5% test, which a fair generator does about 1 time in 20. The test needs enough draws in every bar (NIST/SEMATECH e-Handbook, section 1.3.5.15), so it is applied only when each bar expects at least 5, the usual rule of thumb.
History
| Numbers | Range, time | |
|---|---|---|
| 1 | 68 | 1 to 100Example |
1 draw this visit, kept in this tab only.
Chance of a repeat
With repeats allowed, each draw from 1 to 100 is independent, so repeats turn up sooner than most people expect. A repeat is more likely than not from 13 draws.
- 2 draws
- 1%
- 5 draws
- 9.65%
- 10 draws
- 37.2%
- 13 draws
- 55.7%
- 20 draws
- 87%
- 50 draws
- over 99.99%
- 100 draws
- over 99.99%
Keyboard shortcuts
- G draws again with the same settings.
- C copies the numbers, in the order shown.
- Both work when no box has focus; click an empty part of the page first if you were typing.
- On the Generate button, Enter or Space also draws again.
How it's worked out
The tool starts from every value your settings allow. From 1 to 100 there are 100 whole numbers. Decimal places set the step between values: 0 to 1 with 2 decimal places has 101 values, from 0.00 to 1.00, and each one is as likely as any other.
Your browser then supplies a raw 32-bit number from crypto.getRandomValues, its cryptographic generator. A raw number can be anything from 0 to 4,294,967,295. Turning it into a value takes a remainder:
Here is how many values are possible. The condition on the right matters. For 1 to 100, is not a multiple of 100: 96 raw numbers are left over at the top. If they were kept, the values 1 to 96 would each have one extra way to come up. So the tool throws away any raw number of 4,294,967,200 or more and draws again. That happens to a share of only 2.2 × 10⁻⁸ of draws, and afterwards every value is reached by exactly 42,949,672 raw numbers. It is one of the unbiased rejection methods Daniel Lemire compares in his 2019 paper on random integers in a range.
With No repeats on, the tool shuffles the list of values and takes the first ones, the Fisher-Yates method in Knuth's The Art of Computer Programming. It works like drawing balls from a bag. Skip drawn numbers keeps that bag between draws, so a number drawn earlier in your visit stays out until you clear the history. Ranges with more than 4,294,967,296 possible values (only reachable with decimals) use a 53-bit raw number built from two draws, with the same rule.
One detail about the very first number. The page is built ahead of time, and a server cannot use your browser's generator. So the number shown before the page finishes loading comes from a seeded generator (mulberry32 with seed 1), which always gives 68 for 1 to 100. As soon as the page loads, your browser replaces it with a fresh draw, and every later draw is fresh as well. The test draws on the chart work the same way.
Worked examples
A club raffle with 250 tickets
Dana sold tickets numbered 1 to 250 and has three prizes. She sets the range to 1 to 250, asks for 3 numbers and turns on No repeats, so no ticket can win twice. There are 2,573,000 possible sets of three winners, all equally likely. If she forgot No repeats, a draw of three would repeat a ticket 1.2% of the time. That is rare, but it would be awkward on the night. The history keeps the draw with its time, and the CSV gives her a record for the club minutes.
Calling on 28 students, one at a time
Mr. Lee wants each student called once. He sets 1 to 28, one number per draw, and turns on Skip drawn numbers. In a sample run of 10 calls the numbers came up as 6, 27, 7, 4, 9, 25, 21, 24, 23, 14, and 18 students were still waiting. Without skipping, repeats come quickly: with 28 students, a repeat is more likely than not by call 7, when the chance has reached 55.8%.
Checking that a die is fair
Roll a fair die 600 times and each face should come up about 100 times. Chance alone moves that a lot: 95% of the time a face lands between 82.1 and 117.9. A seeded run of 600 rolls from this tool gave 82, 108, 105, 109, 106, 90 for faces 1 to 6. Face 1 sits just outside its band, yet the chi-square test gives χ² = 6.3 and p = 0.28, nothing unusual. A die that gives 5, 8, 9, 8, 10 and 20 in 60 rolls is different: χ² = 13.4 and p = 0.02, which fails the 5% test.
Reading your result
Every value in the range has the same chance. For one number from 1 to 100, that is 1 in 100. Earlier draws change nothing: the generator has no memory, so a number that just came up is as likely as any other next time.
Repeats are normal when they are allowed. Ten numbers from 1 to 100 contain at least one repeat 37.2% of the time. In a group of 23 people, two share a birthday 50.7% of the time. The Chance of a repeat card shows the same sum for your range. With No repeats, the tiles show how many different sets were possible instead: 13,983,816 for 6 numbers from 1 to 49.
The chart shows how the draws spread across the range. Bars wobble around the dashed line, and about 1 bar in 20 falls outside the shaded band by chance alone. The chi-square test sums those wobbles into one figure. A p-value under 0.05 fails the test, but a fair generator also fails it about 1 time in 20, so one failure means little. Draw again and see if it repeats.
For a long list, the average should sit near the middle of the range and the standard deviation near 29% of its width. For 1 to 100 those are 50.5 and 28.87. Small lists stray further from both.
Common mistakes
- Leaving repeats on for a prize draw. Without No repeats, the same ticket can win twice. Turn it on whenever every number must be different.
- Drawing again until you like the answer. Then the draw is no longer random. For a public draw, announce the range first, draw once, and keep the record.
- Reading a streak as a pattern. Three high numbers in a row do not make a low one due. Each draw is independent; expecting a correction is the gambler's fallacy.
- Rounding a random decimal yourself. Rounding a spreadsheet RAND() to one decimal place gives 0.0 and 1.0 only half the chance of the other values. Setting 1 decimal place here draws from 11 values, 0.0 to 1.0, with equal chances, ends included.
- Forgetting the ends are included. A range of 1 to 10 can give 10. In spreadsheets, RANDBETWEEN(1, 10) also includes both ends, but RAND() never reaches 1.
Questions people ask
Sources
- W3C Web Cryptography API, getRandomValues
- Knuth, D. E. The Art of Computer Programming, Vol. 2: Seminumerical Algorithms, 3rd ed. (random sampling and shuffling)
- Lemire, D. (2019). Fast random integer generation in an interval. ACM TOMACS 29(1)
- NIST/SEMATECH e-Handbook of Statistical Methods, 1.3.5.15 Chi-Square Goodness-of-Fit Test