The Illusion of Randomness: Why Computers Can't Be Truly Random
Exploring pseudo-random number generators, seeds, and why true randomness is fundamentally impossible in deterministic machines.
Have you ever wondered how your computer generates random numbers? The surprising truth is: it doesn't. At least, not truly random ones.
The Determinism Problem
Computers are deterministic machines. Given the same input, they will always produce the same output. This is fantastic for reliability but creates a fundamental problem: how can a deterministic machine produce something unpredictable?
The answer is that it can't — not really. Instead, computers use Pseudo-Random Number Generators (PRNGs).
What is a PRNG?
A PRNG is an algorithm that produces a sequence of numbers that appear random but are actually completely determined by an initial value called a seed.
Here's a simple example of a Linear Congruential Generator (LCG):
next = (a * current + c) mod m
Where a, c, and m are constants. Given the same seed, this formula will produce the exact same sequence every single time.
The Seed: Where "Randomness" Begins
The seed is the starting point for the entire sequence. Common sources for seeds include:
- Current timestamp — milliseconds since epoch
- Mouse movements — user interaction patterns
- CPU temperature — hardware fluctuations
- Keyboard timing — intervals between keystrokes
But here's the catch: if someone knows your seed, they can reproduce your entire "random" sequence.
Why This Matters
Cryptography
Early versions of Netscape's SSL used a predictable seed (process ID + time), allowing attackers to crack encryption. This is why cryptographic applications use Cryptographically Secure PRNGs (CSPRNGs) that gather entropy from multiple unpredictable sources.
Gaming
Speedrunners exploit seeded randomness all the time. In many games, if you perform the same actions at the same frames, you'll get identical "random" outcomes.
Scientific Simulations
Reproducibility is actually a feature here. Scientists can share their seed values so others can verify their Monte Carlo simulations.
True Randomness: Hardware to the Rescue
For applications requiring genuine randomness, we turn to hardware random number generators (HRNGs) that measure physical phenomena:
- Thermal noise in resistors
- Radioactive decay
- Quantum fluctuations
- Atmospheric noise (random.org uses this)
These are truly unpredictable because they're rooted in physical processes that, according to quantum mechanics, are fundamentally indeterminate.
The Philosophical Angle
This raises an interesting question: in a deterministic universe, does true randomness even exist? Some physicists argue that quantum mechanics introduces genuine randomness at the subatomic level. Others, like Einstein, famously disagreed — "God does not play dice with the universe."
Conclusion
Next time you call Math.random() or random.randint(), remember: you're not getting randomness. You're getting a very convincing illusion — a deterministic sequence that's been carefully designed to look chaotic.
And in most cases, that illusion is good enough. But for anything security-critical, make sure you know where your entropy is coming from.
The next time someone asks you for a random number, you can smugly inform them that true randomness is philosophically complicated.