Give the perfect gift for tech-minded kids in your life: 25% off!

dark mode light mode Search Menu


CollegeDegrees360 on Flickr

Randomness is important for all kinds of applications, from securing government secrets and letting you safely communicate on the internet, to making your video games interesting every time you play through each game.

What is randomness and how do you get ahold of “random” data? This simple question is going to lead us from basic algorithms to the weirdness of quantum mechanics.

When people say random numbers they generally mean uniformly random where each number has an equal likelihood of being picked, like a dice roll!

So to do anything random we need a way to generate uniformly random numbers. In fact, we can simplify even further. Any number is a series of digits 0-9, so we can uniformly generate numbers of any size if we can generate a number 0-9 randomly.

Okay, so how can we pick even a single digit randomly? This is where things get tricky.
The problem is that computers aren’t good with randomness. A computer program runs by sending instructions to the processor and the processor interprets them according to the wiring of the circuits at a microscopic level. There’s no room for randomness or choice.

So what do we do? We can either fake randomness on a computer, or get other sources of randomness from the natural world.

Fake Random Numbers

The first option is what people call “pseudo-random number generation,” pseudo being a Greek prefix for fake. We won’t go into detail about how it works but what it does.

Basically, a pseudo-random number generator (PRNG) is a program that will keep giving you numbers each time you ask that are very hard to predict what the next number will be. However, a PRNG will give you the same sequence of numbers every time, which isn’t random at all! That’s why all PRNGs give you the ability to use an input number, a seed, that lets them generate a different sequence for each seed.

If you’ve played a game like The Binding of Isaac or similar games, you may have seen that they’ll tell you what the seed of the game is. That’s a PRNG seed! It’s the thing that’s feeding the pseudo-random number generator the game uses to randomly build levels in the game and what happens in each level.

Randomness from the Natural World

Pseudo-random number generation is good for a lot of uses but not for applications that require randomness, like cryptographic and security protocols where you need to generate hard-to-guess secrets to encrypt data or prove your identity.

There we need help from the natural world, our one true source of randomness and our second option. There’s a lot of ways to get random data from things that happen in nature. A taped-over webcam will output random data based off of the motion of electrons in the camera sensor. The Linux kernel uses the timings of keyboard presses and mouse movements to generate random data. Heck, you can even generate random data at home by rolling dice!

A curmudgeon—okay it’s me—might argue that it’s hard to know that those sources are perfectly random though.

Quantum Random Numbers

There’s one source of randomness that’s definitely, absolutely, unquestionably random: purely quantum mechanical phenomena. Y’see, quantum mechanics—which is our best understanding of how the tiniest particles that make up matter behave—is actually random at its core. So if you can measure a quantum mechanical event, like radioactive decay, then you can turn that into random data.

“Okay, Clarissa, but where am I getting a hold of radioactive materials!” is a very reasonable thing to ask.

Thankfully, there are people who’ve done that part for us. Behold the HotBits site, a source of actual random numbers generated by watching radioactive materials decay. You can use the site to request random data. I did just that, and here’s the 128 bits of data I got back!


That's a string of random hex numbers literally made by nuclear power. Neat!

So that's our brief tour of randomness, computers, and science. Think about it when you're reading the other articles in this issue on randomly generating music, scenery, or game lore! While computers struggle to act in random ways, it is possible to generate random data that’s good enough for computing.

Learn More

The HotBits site, for getting random data from radioactive sources

Another source of truly random data

A cool article on how to take weak sources of randomness and turn them into something way more useful