Random Number Generator
runs in your browserDraw random numbers in any range: one, or a hundred, with or without repeats, sorted or as drawn. Fair draws in your browser.
Draw one number from 1 to 100. That is 100 to choose from.
about this tool
A number, or a hundred of them
Set the two ends of the range, say how many you want, and draw. Both ends are included, so 1 to 6 is a die and 0 to 255 is a byte. Negative numbers are fine.
All different is on by default, because that is what a draw usually means: six lottery numbers, three winners out of a list, a random order. Turn it off when repeats are the point, such as four digits of a PIN, where insisting they differ would quietly make the result less random rather than more.
Why the draw is fair
Two things are easy to get wrong here and both are the whole job.
The source is the browser's cryptographic random generator, not Math.random,
which browsers are free to implement however they like.
The range is then taken by rejection sampling rather than a remainder. A 32-bit number is not a multiple of six, so turning one into a number from 1 to 6 with a remainder hands the low numbers a few extra chances. The fix is to discard the values in the short leftover tail and draw again, which costs an occasional extra draw and nothing else.
Two ways of drawing without repeats
Asking for most of a small range and a handful out of an enormous one are different problems, so there are two methods.
For a small range where you want much of it, the whole range is shuffled and the front of it taken. Exact, and it cannot stall.
For a few numbers out of a large range, numbers are drawn one at a time and any already held is drawn again. Shuffling a range of a billion would mean building a billion-entry list first, which is gigabytes of memory for ten numbers.
The limit either way is about 4.3 billion numbers in the range, which is where a single fair draw from a 32-bit source stops being able to reach the top. Ask for a wider one and it says so rather than never drawing the high numbers.
What it is not for
This is a toy and a convenience, not a source of randomness for anything that matters. Do not use it to run a prize draw someone could contest, to pick lottery numbers you intend to sell, or to generate a key. A page cannot prove to anyone else that it did not choose the answer first.
Nothing is stored between visits, so the numbers are gone when you leave. Copy them if they matter.
If you want dice notation rather than a plain range — four dice keeping the highest three, say — the dice roller speaks it.
questions
- Can I draw numbers with no repeats?
- Yes, and it is on by default. Turn it off to allow the same number more than once, which is what you want for something like four PIN digits and not what you want for lottery numbers.
- How do I pick lottery numbers?
- Set the range to 1 to 49, ask for 6, and leave all-different on. The preset does exactly that and sorts them low to high. Nothing about a random draw improves your odds, which are the same for every ticket.
- Is this actually random?
- It uses the browser’s cryptographic random source rather than the ordinary one, and takes the range without the rounding bias that makes a naive generator favour its low numbers. It is not suitable for a lottery you are running, or anything where someone could gain by predicting it.
- How large a range can it handle?
- Up to about 4.3 billion numbers, which is where a single fair draw from a 32-bit source stops being able to reach the top of the range. Ask for more and it says so rather than quietly never drawing the high numbers.
- Are my numbers saved?
- No. Nothing is stored on your device and nothing is sent anywhere, so a refresh starts again. Copy them if they matter.