Challenge 4-1: RandomNess

Types of Randomness

You probably have a pretty good idea of what it means to be random - unpredictable, unexpected behaviour. But randomness has a pretty specific meaning in computer science and programming, which we'll take you through here.

In computer science, randomness is the concept of generating a number where it’s impossible to know what number it will be beforehand. Rolling a dice is an example of a random process, but computers can’t roll dice every time they need a random number! They need some other way to generate these numbers, and that's where the two different types of randomness come in.

First, hardware random-number generation (or "true" randomness) uses the values of an existing physical environment to generate a number that can be truly impossible to predict.

For example, a computer could use the voltage of a power supply and run a function on it to generate a random number. This works because the voltage will vary by a tiny, unpredictable amount.

This is just one example, and computers can use many environmental values to generate this number. One computer system even uses a camera pointed at a wall of lava lamps to help keep internet banking secure! Watch this video for more info about that and other environmental sources of randomness.

The second type of random number generation (aka rng) is called pseudo-rng, and is used to emulate a hardware rng system. The generated numbers look random, but actually aren’t as they can be reproduced if the starting point is known.

There is a complex algorithm behind the generation of these random numbers, and an initial seed is inputted into this algorithm to achieve the output number. Pseudo-random systems are much more widely used than hardware randomness, because they are far easier and cheaper to implement and can be done purely in code.