How random number generators work
Published by InstantToolDeck · Updated November 2026
Computers are deterministic machines, so “random” numbers need explaining. Understanding the difference between kinds of randomness helps you pick the right tool, whether you are drawing a raffle winner, rolling dice or generating a password.
Pseudo-random generators
A pseudo-random number generator (PRNG) starts from a seed and applies a formula to produce a long sequence that looks random. The same seed gives the same sequence, which is useful for reproducible simulations and games but unsuitable for security, because someone who learns the internal state can predict future values. JavaScript’s Math.random() is this kind.
Cryptographically secure generators
A secure generator (CSPRNG) is seeded from unpredictable sources such as hardware events and the operating system. Browsers expose it as crypto.getRandomValues(). Our random number generator, dice roller, password generator and UUID generator use this source, so the results cannot be predicted from earlier ones.
Modulo bias: a subtle bug
A common shortcut for a number from 1 to 10 is to take a big random number and use the remainder after dividing by 10. If the range of the source is not an exact multiple of 10, some results appear slightly more often. The fair method is rejection sampling: throw away values from the uneven tail and draw again. Careful tools do this so every result is equally likely.
Shuffling fairly
Sorting a list with a random comparison looks plausible but produces uneven orders. The correct approach is the Fisher–Yates shuffle: go through the list from the end, swap each item with a randomly chosen item at or before it. Every ordering is then equally likely. The list shuffler and the random order generator use it.
The odds behind lottery picks
| Game format | Combinations | Chance of the jackpot |
|---|---|---|
| 6 numbers from 49 | 13,983,816 | 1 in 13,983,816 |
| 6 numbers from 45 | 8,145,060 | 1 in 8,145,060 |
| 5 from 69 plus 1 from 26 (Powerball format) | 292,201,338 | 1 in 292,201,338 |
| 5 from 50 plus 2 from 12 (EuroMillions format) | 139,838,160 | 1 in 139,838,160 |
Every combination has the same chance. A generator cannot raise your odds, and 1-2-3-4-5-6 is exactly as likely as any other line. One thing a quick pick can do is avoid popular choices: many players choose birthdays, so numbers above 31 are picked less often, and if a jackpot is won you are less likely to share it. That changes the payout, not the probability of winning. Use the lottery number generator for unique numbers in any range.
The gambler’s fallacy
Random events have no memory. After ten heads in a row a fair coin is still 50 percent heads on the next flip, and a number that has not come up for a long time is not “due”. Streaks are normal in real random data; a sequence with no repeats or runs would actually be suspicious.
When true randomness matters
- Security: passwords, keys and tokens need a CSPRNG.
- Fairness: raffles and draws need uniform selection without bias.
- Games and tests: a seeded PRNG is better when you need repeatable results.
Frequently asked questions
Is Math.random() secure?
No. It is fine for casual uses like shuffling a quiz, but it should not be used for passwords, tokens or anything an attacker could benefit from predicting.
Can a generator improve my lottery odds?
No. Every combination is equally likely, so a generator only saves you from choosing.
What is modulo bias?
A small unfairness that appears when a random value is mapped to a range using the remainder and the range does not divide evenly.
Why do random sequences have streaks?
Because each draw is independent. Streaks and repeats are a normal part of random data.