How a random number generator works
Your browser has a built-in cryptographically strong random number generator, seeded with truly random values. This page takes random bits from it and turns them into a number in your range so that every number is exactly equally likely: it uses just enough bits to cover the range and draws again when they land past the end, instead of dividing and keeping the remainder (which would favour some numbers). Here it is with your numbers:
Here it is with your numbers:
- Possible numbers = 100 − 1 + 1
- Possible numbers = 100
- Random bits needed = 7 (whole numbers 0 to 127; 100 or more is drawn again)
- Your number = 1 + 41
- Your number = 42
It means every whole number from 1 to 100 had the same 1 in 100 chance.
With No repeats, a number that has already come up is drawn again, so each new number is equally likely among the ones left. It works for negative numbers and for ranges up to 9,007,199,254,740,992 numbers, the most a browser counts exactly.
Source W3C · Web Cryptography Level 2, the Crypto interface ↗
Is a random number generator truly random?
Computers follow instructions, so most generators are pseudorandom: a deterministic formula that stretches a short, truly random seed into a long sequence that looks random. What matters is whether anyone can predict it. A cryptographic generator, the kind used here, is built so that its output can’t be predicted without the secret seed.
Source NIST · Glossary, pseudorandom number generator ↗
Random number generator examples
| To pick | Settings |
|---|---|
| A number from 1 to 10 | 1 – 10, 1 number |
| A raffle winner from 250 tickets | 1 – 250, 1 number |
| 3 winners from 30 entries | 1 – 30, 3 numbers, no repeats |
| A random order for 12 people | 1 – 12, 12 numbers, no repeats |
| 6 lottery-style numbers | 1 – 49, 6 numbers, no repeats |
| A number from −10 to 10 | −10 – 10, 1 number |
FAQs
Is any random number generator truly random?
Most, including this one, are pseudorandom: a formula that turns a truly random starting value (the seed) into a long run of numbers that look random. Your browser’s generator is seeded with truly random values from the device, and its output is built to be unpredictable.
Source W3C · Web Cryptography Level 2, the Crypto interface ↗
Is rand() actually random?
No. Functions like rand() in programming languages are pseudorandom number generators: deterministic algorithms that give the same numbers again from the same seed. That is fine for games and simulations, but not where someone could gain by predicting the next number.
Can random number generators be manipulated?
A simple generator can be predicted once someone knows its seed. A cryptographic generator, like the one this page uses, is built so its output is unpredictable as long as the seed is secret. The numbers here are drawn in your browser each time; we never see them.