Random number generator
Pick one number, or up to 10,000, between any two numbers you choose, with both ends included and every number equally likely. Tick No repeats when each number has to be different, as in a raffle or a lottery pick. It runs in your browser; nothing you enter is uploaded.
How the numbers are picked
Every number comes from crypto.getRandomValues, the random number generator browsers provide for cryptography, not from Math.random. The browser seeds it from the operating system's secure generator, so nobody can work out the next number from the ones before it.
The generator also makes sure no number in your range is favored. For 1 to 6, the generator draws a random 32-bit number, from 0 to 4,294,967,295, and keeps the remainder after dividing by 6, which gives 0 to 5. Adding the lowest number, 1, gives 1 to 6.
But the 4,294,967,296 possible 32-bit numbers don't split evenly into 6 groups: four are left over, and they'd make 1 to 4 come up a tiny bit more often than 5 and 6. The generator throws those four values away and draws again, so every number has exactly the same chance. A range too wide for 32 bits, up to 100 digits long, gets as many random bits as it needs and the same check.
With decimal places set to 2, the numbers from 0 to 1 are 0.00, 0.01 and so on up to 1.00: 101 numbers, each equally likely. Every result has exactly that many decimal places, so 0.50 stays 0.50.
Repeats or no repeats
With No repeats unticked, each pick is a fresh draw, like rolling a die again, so the same number can come up twice. That happens sooner than most people expect. Ten numbers from 1 to 100 have about a 37% chance of including at least one pair, and for six numbers from 1 to 49 it's about 27%.
With No repeats ticked, the tool works like drawing tickets from a hat without putting them back. If you ask for more different numbers than the range holds, such as 11 from 1 to 10, you get an error saying so, not a shorter list. Ask for every number in the range, such as 30 from 1 to 30, and you get each one once in a random order, which is a quick way to shuffle a numbered list.
Picking winners, lottery numbers and samples
- Giveaways and raffles: number the entries, then pick one number from 1 to the number of entries. Keep the numbered list, so anyone who asks can see which entry the winning number belongs to.
- Lottery numbers: set the range and how many numbers your lottery uses, such as 6 from 1 to 49, and keep No repeats ticked. There are 13,983,816 ways to pick 6 from 49, and a random pick has the same chance as any other. Random numbers can help in one way, though. Many players use birthdays, which favors 1 to 31, so a winning ticket made only of those numbers is more likely to share the jackpot.
- Spot checks: to check 20 of 500 invoices, pick 20 from 1 to 500 with No repeats and Lowest first, then go through the pile in order.
Other ways to get random numbers
-
In Excel and Google Sheets,
=RANDBETWEEN(1, 100)gives a whole number from 1 to 100. It changes every time the sheet recalculates, so paste it as a value to keep it. - On Linux,
shuf -i 1-49 -n 6prints 6 different numbers from 1 to 49. Add-rto allow repeats. -
In Python,
random.randint(1, 100)picks one number with both ends included, andrandom.sample(range(1, 50), 6)picks 6 different ones. When someone might gain from predicting the result, use thesecretsmodule instead:secrets.randbelow(100) + 1gives 1 to 100.