Calculators & everyday math
Random vs. Pseudorandom Numbers
A pseudorandom sequence looks random but is completely determined by a formula and a starting value. That sounds like a flaw, but reproducibility is exactly what simulations and testing need. This guide shows how a pseudorandom generator works, using one small enough to follow by hand, and when predictability matters.
Ready to try the tool this guide describes?
What pseudorandom means
A pseudorandom number generator (PRNG) applies the same formula to its last output to get the next one. Given the same seed, it produces the same sequence every time. Good generators pass statistical tests of randomness even though every value is predetermined.
A tiny generator you can follow
A linear congruential generator uses x(next) = (a × x + c) mod m. With a = 5, c = 3, m = 16, and seed 7: (5 × 7 + 3) mod 16 = 38 mod 16 = 6, then (5 × 6 + 3) mod 16 = 1, and so on.
| Step | Values |
|---|---|
| 1–8 | 6, 1, 8, 11, 10, 5, 12, 15 |
| 9–16 | 14, 9, 0, 3, 2, 13, 4, 7 |
| 17–20 | 6, 1, 8, 11 |
After 16 values the sequence starts again: its period is 16. Real generators use enormous values of m so the period is far longer than any program will need.
When predictability helps
- Scientific simulations can be rerun exactly by reusing the seed.
- Games can recreate a level or a shuffled deck from a saved seed.
- Software tests can repeat a “random” scenario that found a bug.
When predictability is a problem
If someone can learn the seed or enough outputs, they can predict the rest of the sequence. That is fine for a board game and unacceptable for passwords, encryption keys, or anything with money at stake. Cryptographically secure generators are designed so the next output can’t practically be predicted from earlier ones, and they are reseeded with fresh hardware entropy.
What the Random Number Generator uses
It uses the browser’s crypto.getRandomValues(), a cryptographically secure generator seeded by the operating system, so there is no seed to set or repeat. It is still meant for everyday picks rather than security or gambling.
Random vs. Pseudorandom FAQ
- Are pseudorandom numbers really random?
- No. They are determined by a formula and a seed, but good generators are statistically very hard to tell apart from random.
- What is the period of a generator?
- How many values it produces before the sequence repeats.
- Why would I want the same random sequence twice?
- To repeat a simulation, recreate a game, or rerun a test exactly.
- What makes a generator cryptographically secure?
- Its future outputs can’t practically be predicted from past ones, even by someone who knows the algorithm.
- Can I set a seed in the Random Number Generator?
- No. It draws from the browser’s secure generator, which has no user-set seed.
Related guides
- How RNGs WorkWhere computers get randomness, the difference between hardware and algorithmic generators, how browsers expose them, and which suits which job.
- Random Integer in a RangeCount an inclusive range correctly, map random values onto it, avoid modulo bias, and handle negative ranges and spreadsheets.
Open the tool
Jump into Random Number Generator when you are ready to process your files.
