How Computers Fake Randomness (and Why It Works)

Picture this: You’re watching the evening lottery draw on TV. The shiny machine tumbles colorful balls around, and one by one, the winning numbers are selected. But what if I told you that those numbers weren’t actually random at all? What if someone could predict exactly which balls would drop, making the entire lottery a sham?

Aug 14, 2025 9 min read Originally published on Medium
  • computer science
  • randomness
  • technology
Article illustration

Originally published on Medium. This version is now archived under /blogs.

Picture this: You’re watching the evening lottery draw on TV. The shiny machine tumbles colorful balls around, and one by one, the winning numbers are selected. But what if I told you that those numbers weren’t actually random at all? What if someone could predict exactly which balls would drop, making the entire lottery a sham?

Suddenly, that innocent game of chance doesn’t seem so fair anymore, does it? This scenario might sound like something out of a thriller movie, but it touches on a fundamental challenge that affects every aspect of our digital lives: the quest for true randomness.

Why We Desperately Need Random Numbers

Random numbers are the invisible heroes of our modern world. They’re working behind the scenes in ways you probably never imagined.

Every time you shuffle your Spotify playlist, random numbers decide which song plays next. When you’re playing an online game and a treasure chest appears in an unexpected location, that’s randomness at work. When you flip a coin using your phone’s app, the result comes from a random number generator.

But here’s where things get really interesting, and really important. Random numbers aren’t just for entertainment. They’re the foundation of digital security. Every time you log into your bank account, shop online, or send a private message, random numbers are protecting you.

Think about it: when you create a new password, how does your computer suggest “J8$mK9!pL2” instead of “password123”? Random numbers. When your browser establishes a secure connection to your bank’s website, it uses random numbers to create encryption keys that keep your financial information safe from prying eyes.

The stakes are higher than you might think. In 2008, a flaw in random number generation left millions of computers vulnerable to attack. Hackers could break encryption that should have taken billions of years to crack. In 2012, researchers found they could predict “random” numbers in online poker games, potentially allowing players to cheat. When randomness fails, security crumbles.

The Impossible Dream: Truly Random Numbers

Here’s the thing that might blow your mind: computers are terrible at being random. In fact, they’re designed to be the complete opposite of random.

A computer is basically the world’s most obedient servant. You give it instructions, and it follows them exactly, every single time. Ask a computer to add 2 + 2, and it will always give you 4. Ask it to open a file, and it will open that exact file. Computers are predictable, reliable, and deterministic, which is exactly why they’re so useful.

But this creates a fascinating paradox. How do you ask a machine that always follows rules to break the rules and give you something unpredictable?

It’s like asking a calculator to “think of a number between 1 and 100.” The calculator doesn’t have imagination or intuition. It can only do what it’s programmed to do. If you programmed it to always answer “42,” then it will always answer “42.” If you programmed it to count up from 1, it will always start with 1, then 2, then 3, and so on.

For true randomness, you’d need something genuinely unpredictable: the exact moment a radioactive atom decays, the precise pattern of raindrops hitting your window, or the chaotic movement of molecules bouncing around in a gas. These physical phenomena are fundamentally unpredictable, even in theory.

The Clever Workaround: Fake It Till You Make It

Since computers can’t create true randomness, programmers came up with a brilliant solution: let’s fake it so well that nobody can tell the difference.

Enter pseudo-random number generators, or PRNGs for short. Think of them as incredibly sophisticated recipes for creating sequences of numbers that look random, even though they’re generated by following precise mathematical instructions.

Here’s a simple way to understand how this works: imagine I give you a recipe that says “Start with the number 7. Multiply it by 13, add 5, then only keep the last digit.” Following this recipe:

  • Start with 7
  • 7 × 13 = 91, plus 5 = 96, last digit = 6
  • Take 6: 6 × 13 = 78, plus 5 = 83, last digit = 3
  • Take 3: 3 × 13 = 39, plus 5 = 44, last digit = 4
  • Take 4: 4 × 13 = 52, plus 5 = 57, last digit = 7

So we get the sequence: 7, 6, 3, 4, 7… and it continues from there.

This sequence looks pretty random if you don’t know the recipe. But here’s the crucial insight: if you start with the same “seed” number (7 in our example), you’ll always get the exact same sequence. That’s why these generators are called “pseudo-random” ,they’re not truly random, just really good at pretending to be.

The starting number (that initial 7) is called the “seed.” It’s like the secret ingredient that determines everything that follows. Change the seed to 8, and you’ll get a completely different sequence that still looks random.

How These Mathematical Magicians Actually Work

The recipe I described above is actually a simplified version of one of the oldest and most famous pseudo-random number generators, called a Linear Congruential Generator. Real PRNGs use much more complex mathematical formulas, but the principle is the same.

Modern PRNGs are incredibly sophisticated. They use advanced mathematics to create sequences that can go on for billions or even trillions of numbers before they start repeating. Some are designed to pass extremely rigorous statistical tests: examinations so thorough they would spot patterns that human eyes could never detect.

But here’s the catch: no matter how complex the formula, every PRNG will eventually repeat itself. It’s like a very, very long loop. Once you’ve seen all the numbers in the sequence, it starts over from the beginning. For a good PRNG, this “period” is so long that you’d never notice in practical use. We’re talking about sequences longer than the number of atoms in the observable universe.

The beauty of PRNGs lies in their balance: they’re predictable enough that programmers can reproduce the same sequence when needed (crucial for debugging software), but unpredictable enough that an attacker can’t easily guess what comes next.

When Good Enough Isn’t Good Enough

For most everyday applications (shuffling your music, generating random levels in video games, running statistical simulations) pseudo-random numbers work perfectly fine. They’re fast, reliable, and “random enough” for these purposes.

But what about when you’re protecting nuclear launch codes? Or securing transactions worth millions of dollars? Or generating the cryptographic keys that protect national secrets?

Suddenly, “good enough” doesn’t feel quite good enough anymore.

This is where the limitations of pseudo-random generators become a real problem. Because PRNGs follow mathematical rules, a determined attacker with enough computing power might be able to figure out the pattern and predict future numbers. It’s like playing poker against someone who’s figured out how you shuffle the deck. They might not know every card, but they have a dangerous advantage.

For high-security applications, we need something better. We need true randomness.

Enter the Lava Lamps: Cloudflare’s Beautiful Solution

This brings us to one of the most delightful and unexpected solutions in the world of cybersecurity: Cloudflare’s wall of lava lamps.

Article illustration
Cloudflare’s wall of lava lamps

Cloudflare is a company that helps protect and speed up websites all over the internet. They handle enormous amounts of web traffic and need truly random numbers to keep everything secure. Their solution? A wall of about 100 lava lamps in their San Francisco office.

Here’s how this wonderfully weird system works: A camera points at the wall of lava lamps, taking pictures throughout the day. Each photo captures the unpredictable, chaotic movement of the waxy blobs floating inside each lamp. The exact position of every bubble, every swirl of wax, every play of light and shadow is genuinely unpredictable. It’s influenced by tiny variations in temperature, air currents, vibrations from passing trucks, and countless other factors that no computer could ever calculate or predict.

The camera converts these images into streams of numbers representing the color and brightness of each pixel. These numbers become the seeds for cryptographic systems that help protect millions of websites around the world.

Why is this approach so brilliant? Because the movement of wax in lava lamps is a truly chaotic physical process. Unlike the deterministic world of computers, the real world is full of genuine randomness. The exact moment when a blob of wax will rise to the top of a lamp is influenced by quantum mechanics, thermal dynamics, and countless other factors that make it fundamentally unpredictable.

It’s a perfect marriage of the physical and digital worlds. The chaotic beauty of lava lamps (originally designed as 1960s home decor) now helps secure the modern internet. There’s something almost poetic about using these symbols of psychedelic creativity to generate the mathematical foundations of digital security.

Cloudflare isn’t alone in seeking randomness from the physical world. Other companies and organizations use everything from atmospheric noise to quantum mechanical processes to the timing of keystrokes and mouse movements. The quest for true randomness has led to some of the most creative solutions in computer science.

Living in a Random World

Our journey through the world of random numbers reveals something fascinating about the relationship between order and chaos in our digital age. We’ve built incredibly orderly, predictable machines (computers) and then spent decades figuring out how to make them behave unpredictably when we need them to.

We started with a simple need: fair lottery drawings and shuffled playlists. But we discovered that randomness is actually one of the fundamental building blocks of digital security. Without good random numbers, our online banking would be vulnerable, our private messages could be intercepted, and our digital identities could be stolen.

The solution required both mathematical ingenuity and creative thinking. Pseudo-random number generators give us “good enough” randomness for everyday use, using elegant mathematical recipes to create the illusion of chaos. When we need something stronger, we turn to the physical world: to lava lamps and atmospheric noise and quantum uncertainty, to inject genuine unpredictability into our deterministic machines.

This invisible technology is working right now as you read this. Random numbers helped secure the connection between your device and the server hosting this blog post. They’re protecting your data, shuffling your feeds, and adding an element of chance to countless digital experiences.

The next time you see a lava lamp, remember: you’re looking at a piece of technology that’s helping keep the internet secure. In our quest to build predictable machines, we discovered we also needed a little bit of beautiful, chaotic randomness. And sometimes, the most elegant solutions come from the most unexpected places.

Sometimes the best way forward isn’t more code or faster processors ; it’s simply watching the wax dance.

Read Up:

  1. https://blog.cloudflare.com/randomness-101-lavarand-in-production
  2. https://www.hawking.org.uk/in-words/lectures/does-god-play-dice
  3. http://link.springer.com/article/10.1023/A:1007509231135