Random number generator
Choose a range and how many numbers you need. Tick No repeats for raffle-style draws where every number is different.
Your numbers will sprout here.
1 number from 1 to 100.
How the numbers are picked
Set the lowest and highest values (both can come up, and negatives are fine) and how many numbers you want. No repeats makes every number different, like drawing raffle tickets; untick it to let numbers repeat, like rolling the same die again and again. Order sorts the results after they are drawn, which makes long lists easier to check.
Each number comes from crypto.getRandomValues, the Web Crypto generator that browsers feed from the operating system's secure random source. It deals in 32-bit values, and squeezing one into 1 to 100 with a plain remainder would favour some results slightly, because 4,294,967,296 is not a multiple of 100. So values from the uneven top end are thrown away and drawn again (rejection sampling), and every number in your range is exactly as likely as any other.
Without repeats, small ranges are shuffled partway with the Fisher–Yates method and huge ranges use Robert Floyd's sampling algorithm, which never needs to list every number. With repeats allowed, the line under the result shows the chance that at least two numbers match.
Sources
- W3C, Web Cryptography API: the getRandomValues method. MDN, Crypto: getRandomValues().
- Knuth DE. The Art of Computer Programming, Vol. 2: Seminumerical Algorithms, 3rd ed. Addison-Wesley, 1997, section 3.4.2 (shuffling and sampling).
- Bentley J, Floyd B. Programming pearls: a sample of brilliance. Communications of the ACM 1987;30(9).
Questions
Are these numbers truly random?
They come from your browser's cryptographically secure generator, the kind of source used to make encryption keys. They cannot be predicted in practice, and every number in your range has the same chance.
Why did a number repeat?
Repeats are allowed until you tick No repeats, and matches come sooner than most people expect: 12 numbers from 1 to 100 contain a repeat about half the time.
How big can the range be?
Any whole numbers from minus one quadrillion to one quadrillion (1,000,000,000,000,000), and up to 10,000 numbers per draw.