beanz Magazine

Randomness

CollegeDegrees360 on Flickr

Take a peek into the importance — and the struggle — of getting truly random data.

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!


4D78E36D1EE2DFDADACF8B43FC9AF5DD758C14B27845B13B00BDAFC6F7FB3359
FD7631AF5B3793E9694DD5FDFFBAAABFD3C7F6A9EE27FC2C4C3A99A09D63D5F0
B245EBDF648F8FFCF8786618A86F3097049D8DC0434F5080121BF9A84B7EC431
201324103C3D8D07AD8BC43196D006FDC87180C9B6585646050AA4710891383C

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

https://www.fourmilab.ch/hotbits/

Another source of truly random data

https://www.random.org/

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

https://blog.cloudflare.com/ensuring-randomness-with-linuxs-random-number-generator/

Also In The December 2019 Issue

30+ ideas for STEAM-theme gifts for kids of all ages!

Visual storytelling apps are a great way for kids to document and explore their lives.

Meet 16-year old Astronaut StarBright, whose activism is inspiring the next generation of STEM fans.

Dive into the first “console wars” and learn how more bits led to bigger and better games.

From the start of computing history, people have tried to optimize the software programming process. This includes having two coders work together to code software.

Explore the solar system and test your knowledge of space through this fun coding activity.

Learn how procedural generation can be used to create infinite maps, music, and worlds to explore.

The Wayback Machine lets you travel back in time to see old websites. Plus the Internet Archive has thousands of vintage games, software, books, and more.

Online research skills are critical for software programmers. It's how you learn any language, by searching for error messages and looking up reference material.

How rural America connected itself to the phone grid using barbed wire, glass bottles, and even corncobs!

Meet Cozmo, the clever new robot that’s bringing AI concepts to life for kids as young as 5-7 years old.

Throw some festive ornaments on a virtual Christmas Tree in this fun introduction to functional programming.

How the Internet of Things could improve education, from VR to accessibility to facial recognition.

No one wants to deal with viruses over the holidays. Here’s how to protect your new devices!

Some digital tools to help you create your own unique, ever-changing symphony with nothing but some code and a computer!

Take a peek into the importance — and the struggle — of getting truly random data.

Interesting stories about computer science, software programming, and technology for December 2019.

Links from the bottom of all the December 2019 articles, collected in one place for you to print, share, or bookmark.