Menu

Random number generator

Whole numbers or decimals between any two values, one at a time or as a list, with or without repeats.

Common ranges:

73

73, drawn from the 100 whole numbers from 1 to 100. Each had the same 1 in 100 chance.

About this result
Possible values100
Chance of this number1 in 100
Chance of the same number next time1 in 100

How a fair number is chosen

A computer’s random generator gives raw random bits, not numbers from 1 to 100, so every generator has to map those bits to your range. The obvious method, taking the remainder after dividing by the size of the range, is subtly unfair whenever the range doesn’t divide the number of possible bit patterns evenly.

A random byte shows the problem clearly. A byte has 256 values. Divide by 100 and keep the remainder, and the remainders 0 to 55 can each be reached three ways (for example 5, 105 and 205), while 56 to 99 can be reached only two ways.

Method, byte (0–255) to 100 valuesChance of 0–55Chance of 56–99
Remainder after dividing by 1003 in 256 (1.17%)2 in 256 (0.78%)
Rejection: redraw bytes 200 to 255, then take the remainder2 in 200 (1%)2 in 200 (1%)

This generator uses rejection with 32-bit blocks. For a range of 100 it discards the top 96 of the 4,294,967,296 possible blocks and draws again, which happens about once in 45 million draws, and every number in the range ends up with exactly the same chance. Ranges larger than about 4.3 thousand million use 53 random bits the same way.

Repeats, and how often they happen

When repeats are allowed, each draw ignores the ones before it, so the chance of a repeat grows quickly with the number of draws. It is the same arithmetic as the birthday problem, in which 23 people have a better than even chance of two sharing a birthday. For k draws from N values, the chance that all are different is:

all different= N × (N − 1) × … × (N − k + 1) ÷ Nk10 from 100: 62.8%

a repeat= 1 − chance all different10 from 100: 37.2%

DrawsFrom 1–100From 1–1,000From 1–10,000
59.7%1.0%0.1%
1037.2%4.4%0.4%
2087.0%17.4%1.9%
3099.2%35.6%4.3%
50Almost 100%71.2%11.5%
100Almost 100%99.4%39.1%

If the numbers must all be different, as for raffle tickets, seat numbers or a lottery line, tick “No repeats”. The generator then draws from the values still left, like balls leaving a machine, and refuses to run if you ask for more numbers than the range holds.

Decimals and left-out numbers

With decimal places, the range is divided into equal steps. From 0 to 1 at two places there are 101 possible values, 0.00, 0.01 and so on up to 1.00, and each has a 1 in 101 chance. Both ends can come up, unlike many programming functions that return a decimal from 0 up to but not including 1.

Numbers you leave out are removed before the draw, not redrawn afterwards, so the remaining numbers share the chance equally. Leaving out 13 from 1 to 20 gives each of the other 19 numbers a 1 in 19 chance. Write single numbers and ranges separated by commas, such as 13, 20-25; with decimal places the values are matched at that precision.

Choosing the right settings

You wantSettings
A winner from 250 numbered entriesLowest 1, highest 250, how many 1
Three different prize winners from 250How many 3, no repeats, order as drawn (first drawn wins first prize)
A random order for 30 students1 to 30, how many 30, no repeats
Ten test scores between 40 and 10040 to 100, how many 10, repeats allowed
A random price between 5 and 205 to 20, two decimal places
A number from 1 to 100 that isn’t a multiple of 10Leave out 10, 20, 30, 40, 50, 60, 70, 80, 90, 100

Questions

Are the lowest and highest numbers included?

Yes. A range of 1 to 10 can give 1 and can give 10, and each of the ten numbers has the same 1 in 10 chance.

Why did the same number come up twice?

With repeats allowed, every draw starts from the full range, so repeats are normal and happen more often than most people expect. Ten numbers from 1 to 100 contain at least one repeat 37.2% of the time. Tick “No repeats” if every number must be different.

Is this truly random?

The numbers come from your browser’s cryptographic random number generator, the same source browsers use for encryption keys. It is a pseudo-random generator seeded by the operating system from hardware events, which makes its output unpredictable in practice. The guide to true random and pseudo-random numbers explains the difference.

Can I use it to pick a winner for a giveaway?

Yes. Number the entries, set the range to match, and generate one number, or as many different numbers as you have prizes. The log of draws records the time and settings of each draw. For a draw from names, the random name picker does the numbering for you, and the guide to running a fair draw covers the record-keeping.

Are my numbers saved or sent anywhere?

No. The numbers are made in your browser and stay there. The address bar keeps your settings, not the results, so a link you share opens the same range but makes new numbers.

Can I get the same numbers again?

No. The generator has no seed you can set, so a draw can’t be repeated. That is what makes it suitable for draws, but if you need a repeatable sequence for testing or research, use a seeded generator in a programming language instead and record the seed.

How large can the range be?

Any range up to about 9 × 10^15 values, which covers every whole number a browser can represent exactly. You can draw up to 10,000 numbers at a time.