Random Number Generator

Pick a range and how many numbers you want. Duplicates are optional.

Last reviewed:

Pseudo-random vs cryptographically secure numbers

Computers are built to be predictable, so producing randomness takes some care. The simplest generators are pseudo-random: a formula takes a starting value called a seed and churns out numbers that look random but repeat exactly if you start from the same seed. That is fine for a video game, and a real weakness anywhere someone could gain by guessing the next number.

This generator uses your browser's cryptographically secure source, crypto.getRandomValues. It is seeded with unpredictable data (entropy) and designed so that earlier results give no useful clue about later ones. The numbers are generated on your own device.

FeatureSimple pseudo-randomCryptographically secure
Starts fromA seed valueUnpredictable entropy
Can be replayedYes, from the same seedNo
Can be guessed from past outputsPossible for simple formulasNot in practice
Typical usesGames, simulations, repeatable testsPasswords, security keys, fair draws
Used hereNoYes

Inclusive ranges and how many numbers are possible

Both ends of the range are included. Ask for a number from 1 to 10 and you can get 1 or 10, with every whole number in between equally likely. The count of possible results is one more than the gap between the ends, which is the classic off-by-one trap.

Possible values = Max − Min + 1
Chance of any one value = 1 ÷ (Max − Min + 1)
RangePossible valuesChance of each
1 to 6616.67%
0 to 91010%
1 to 1001001%
−10 to 10214.76%
1 to 3653650.27%

Results are whole numbers. For decimals, scale up and divide: for a number from 0 to 10 with two decimal places, generate from 0 to 1000 and divide the result by 100.

With or without duplicates

Turning duplicates off is like drawing numbered balls from a bag and keeping them out. Leaving duplicates on is like dropping each ball back in before the next draw. Repeats then turn up far sooner than most people expect; it's the same effect behind the famous birthday problem, where 23 people are enough for a better than even chance of a shared birthday.

Drawing from 1 to 100 with repeats allowed
Numbers drawnChance of at least one repeat
59.7%
1037.2%
1566.9%
2087.0%
3099.2%

So if you need ten different numbers, keep duplicates off. You also can't ask for more unique numbers than the range holds: there are only five different whole numbers from 1 to 5.

Lottery odds formula

In a draw where you choose k numbers out of n and the order doesn't matter, the number of possible tickets comes from the combinations formula. Every ticket has exactly the same chance, including the one that reads 1, 2, 3, 4, 5, 6. It looks too tidy to win, but the draw doesn't know that.

Combinations = n! ÷ (k! × (n − k)!)
n = how many numbers are in the draw
k = how many you pick

Example: pick 6 from 49

  1. (49 × 48 × 47 × 46 × 45 × 44) ÷ (6 × 5 × 4 × 3 × 2 × 1)
  2. 10,068,347,520 ÷ 720
  3. = 13,983,816

One ticket has a 1 in 13,983,816 chance of matching all six numbers.

FormatPossible tickets
Pick 6 from 458,145,060
Pick 5 from 6911,238,513
Pick 6 from 4913,983,816
Pick 6 from 5945,057,474

Drawing raffle winners by ticket number

Numbered tickets make a random number generator the simplest raffle drum there is. Set the range from the first ticket to the last one sold, not the last one printed, or you may draw a ticket nobody holds. Each ticket's chance is 1 divided by the number of tickets, so someone holding several tickets simply has several chances.

Example: a school raffle with three prizes

  1. Tickets 1 to 250 were sold
  2. Generate 3 numbers from 1 to 250 with duplicates off, so no ticket can win twice, and sorting off, so the order stays random
  3. Give the top prize to the first number, the second prize to the next, and so on
  4. A family holding 5 tickets has a 5 ÷ 250 = 2% chance of the top prize

Three different winning tickets, drawn in one go, with the prize order decided in advance.

Everyday uses for random numbers

  • Surprise breaks: generate a minute from 0 to 59 and that's when the class, or the office, gets its five-minute stretch.
  • Surveys and spot checks: to contact 20 of 400 customers, number the list and generate 20 numbers from 1 to 400 with duplicates off.
  • Classrooms: pick a random page, question or seat. For names rather than numbers, the Random Name Picker is quicker.
  • Games: any die you don't own, like a d7 or a d30, is just a range from 1 to 7 or 1 to 30. Standard dice live on the Dice Roller.
  • Running order: to put a whole list in random order, use the List Shuffler.

If there's a prize involved, say the range and the rules out loud before you press the button, and do it where everyone can see the screen. It's much harder to argue with a draw you watched.

Sources and further reading

Every tool in Randomizer

How to use it

  1. 1Set the minimum and maximum.
  2. 2Choose how many numbers and whether repeats are allowed.
  3. 3Press Generate.

Questions

Is it really random?

Yes. Results come from your browser's cryptographically secure random generator (crypto.getRandomValues), the same source used for security keys.

Can I generate lottery numbers?

Yes. Set the range (for example 1 to 49), the count (6) and turn off duplicates.

Also handy: Classroom Timer, Online Timer