Random Number Generator
- Updated
- Formula shown
- Free, no sign-up
Loading…
How to use the random number generator
- Choose whole numbers or decimals. For decimals, set how many decimal places you want (up to 10).
- Enter the minimum and maximum. Both ends can be drawn, and negative values are fine (up to ±1015).
- Set how many numbers you want, whether repeats are allowed, and the order.
- Press Generate for a new set. Copy the list from the box under the results.
How the randomness is produced
The numbers are made in your browser, and nothing is sent to a server. The random bits come from the Web Crypto API, crypto.getRandomValues,
which every modern browser provides. It is a cryptographically secure pseudorandom generator that the browser seeds from your operating system's entropy
source, so its output can't be predicted from earlier numbers.
repeat: x = random bits; until x < range
value = minimum + x × 10−k (k = decimal places)
Turning random bits into a number in a range is where many generators go wrong. The calculator uses rejection sampling: it draws just enough bits to cover the range and simply draws again when the result lands outside it. For a die (range 6), 3 bits give 8 equally likely results; 6 and 7 are thrown away, so 25% of draws are repeated and it takes 1.33 draws on average. Decimals with k places are drawn as whole numbers of 10−k steps, so 0 to 1 with 2 places has 101 equally likely values: 0.00, 0.01, …, 1.00. Without repeats, small ranges are shuffled like a deck of cards (a Fisher–Yates shuffle) and large ranges are drawn with any repeat drawn again.
Worked example: why not just use the remainder?
A tempting shortcut is to take a random 32-bit number and keep the remainder after dividing by the range. 232 = 4,294,967,296 is not a multiple of 100: it leaves a remainder of 96. So the values 0 to 95 would each come up 42,949,673 times in every 232 draws, while 96 to 99 would come up only 42,949,672 times. The difference is tiny, but it is real, and it grows as the range gets larger. Rejection sampling has no such bias.
How often rejection sampling draws again
| Range size | Random bits | Chance of a redraw | Average draws |
|---|---|---|---|
| 2 | 1 | 0% | 1 |
| 6 | 3 | 25% | 1.333 |
| 10 | 4 | 37.5% | 1.6 |
| 49 | 6 | 23.4% | 1.306 |
| 100 | 7 | 21.9% | 1.28 |
| 1,000 | 10 | 2.3% | 1.024 |
| 1,000,000 | 20 | 4.6% | 1.049 |
| 2,147,483,649 | 32 | 50% | 2 |
Even in the worst case, just above a power of 2, a value is found in fewer than 2 draws on average.
Chance of at least one repeat
With repeats allowed, matches turn up sooner than most people expect. Each cell is the chance that k draws from N values include at least one repeat.
| Values (N) | k = 5 | k = 10 | k = 23 | k = 50 | k = 100 |
|---|---|---|---|---|---|
| 10 | 69.8% | > 99.9% | 100% | 100% | 100% |
| 100 | 9.7% | 37.2% | 93.6% | > 99.9% | 100% |
| 365 | 2.7% | 11.7% | 50.7% | 97% | > 99.9% |
| 1,000 | 1% | 4.4% | 22.5% | 71.2% | 99.4% |
| 1,000,000 | < 0.1% | < 0.1% | < 0.1% | 0.1% | 0.5% |
What it is good for, and what it is not
- Good for: games, classroom activities, picking a random student or question, sampling rows from a list, choosing a winner among friends, and testing.
- Not certified for regulated draws. The tool has not been tested or audited for lotteries, gambling or official prize draws, and a web page can't prove to anyone else that a draw was fair. Use the approved method required where you are.
- Not for passwords or keys. Use a dedicated password manager for secrets, so they are never shown on screen or kept in a page address.
- Results are not saved. Reloading or sharing the page gives a fresh set, because each visit draws new numbers.
To see patterns in numbers that are not random, try the number sequence calculator; to turn a count into a percentage, use the percentage calculator.
Frequently asked questions
How are the random numbers generated?
In your browser, with the Web Crypto API's crypto.getRandomValues, a cryptographically secure generator seeded by your operating system. Each number is then picked by rejection sampling: the generator draws just enough random bits to cover the range and draws again if the result falls outside it. Nothing is sent to a server.
Is every number equally likely?
Yes. The common shortcut of taking a random 32-bit number modulo the range is slightly biased: 2³² divided by 100 leaves a remainder of 96, so the values 0 to 95 would come up 42,949,673 times in every 2³² draws and 96 to 99 only 42,949,672 times. Rejection sampling removes that bias completely.
Can I use it for a lottery or a prize draw?
It is fine for informal draws such as picking a raffle ticket among friends. It has not been certified or audited for regulated lotteries, gambling or official prize draws, and a web page cannot prove to other people that a draw was fair, so follow the rules and approved methods that apply where you are.
How do I pick numbers without repeats?
Set Repeats to "No repeats". For example, 6 different numbers from 1 to 49 are drawn like cards from a shuffled deck, so any particular number has a 6 in 49 (about 12.2%) chance of being among them. You can ask for at most as many numbers as the range contains.
Why do repeats turn up so often?
This is the birthday problem. Drawing 10 numbers from 1 to 100 with repeats allowed gives about a 37% chance that at least two match, and 23 draws from 365 values give about 51%. Repeats are a normal part of random data, not a sign that something is wrong.