Random Number Generator

Pick a range, say how many numbers you want, and draw. Every number in the range is exactly as likely as every other — which takes slightly more care than it sounds.

Result


          
—How many
—Lowest drawn
—Highest drawn

How to use it

  1. Set the range. Both ends are included, so 1 to 6 can give you a 1 and it can give you a 6.
  2. Say how many numbers you want.
  3. Tick no repeats if the numbers have to be different from each other — drawing five raffle tickets, not rolling five dice.

Repeats, and why the difference matters

Two people asking for “five random numbers from 1 to 10” often want two different things. Rolling a die five times can easily give you two fours; drawing five names out of ten cannot give you the same name twice. The first is with repeats, the second is without, and getting it backwards quietly ruins a draw.

With no repeats, you cannot ask for more numbers than the range holds. Five different numbers between 1 and 4 do not exist, and the page says so rather than looping forever trying.

Where the randomness comes from

This uses crypto.getRandomValues, the generator built into your browser for keys and passwords, rather than Math.random. For picking a raffle winner either would do; the stronger one is used because there is no reason not to.

The part that is easy to get wrong is the last step. Turning a huge random number into a number from 1 to 100 is usually written as a remainder — value % 100 — and that is not quite fair. The range of the generator does not divide evenly by 100, so the first few numbers come up very slightly more often than the last few. The effect is tiny, and it is real.

The fix is to throw away the handful of values in that leftover tail and draw again. It costs almost nothing and every number in your range becomes exactly as likely as every other. That is the difference between nearly uniform and uniform, and it is worth the four extra lines.

What random does not mean

Random does not mean spread out. Ask for six numbers from 1 to 49 and you may well get two that are next to each other; that is normal, not a fault. A generator that carefully avoided such pairs would be less random, not more.

Frequently asked questions

Are both the From and To numbers included?

Yes. From 1 to 100 can return 1 and can return 100. That is what people expect, and it is worth stating because plenty of programming functions exclude the top end.

Can I use negative numbers?

Yes, and you can put them in either box - from -50 to 50 works, and so does typing them the wrong way round, which is simply swapped for you.

Is this random enough for a prize draw?

The numbers themselves, yes - this is the same generator your browser uses for encryption keys. What a web page cannot do is prove to somebody else that you did not press Draw twenty times until you liked the answer. For anything contested, record your screen while you draw once.

Why did I get the same number twice?

Because repeats are allowed unless you tick the box. Two fours in five die rolls is ordinary. If every number must be different, tick 'no repeats'.

What is the biggest range I can use?

Up to about nine quadrillion, which is the largest whole number JavaScript can hold exactly. Past that the page would start quietly rounding, so it refuses instead of pretending.

Is my text sent anywhere?

No. Everything happens in JavaScript inside your own browser. Nothing is uploaded and nothing is saved - close the tab and it is gone.

Related tools