How does a computer generate a random number?

With development languages ​​that are increasingly high level, we sometimes come to no longer wonder how exactly it works under the hood. For example, how do you get a computer to generate a random number, which is in essence the opposite of what a machine does?

This article is based on a discussion between colleagues. With our development issues, we worry about our algorithms, how to implement what is expected. But we are at a level that is now very far from the machine. We come to no longer ask ourselves the question of how it works at a very low level.

Random numbers are a very good example. For the developer, nothing could be simpler. A rand() or random() function depending on the language used and that’s it. But when we look at the subject, we say to ourselves that chance in computing does not exist. Nothing is more deterministic and rational. Randomness does not exist, there can only be pseudo randomness based on things that are unpredictable enough to give the impression of randomness. There are several possibilities for this.

Chance on physical events

One of the best methods is to rely on physical events: electromagnetic noise, thermal noise, radioactivity… with a hardware generator. The idea is to amplify this sufficiently unpredictable physical event, measure it and turn it into a number, often between 0 and 1.

Quantum method

A very reliable method, but still in development, is based on the quantum properties of photons. Indeed, quantum phenomena are by nature indeterminate and therefore unpredictable. Existing methods often use the way photons behave in front of a mirror. The photon can either be reflected or pass through the mirror. This phenomenon is purely random and therefore can be used to generate a series of 0s and 1s depending on this phenomenon.

Algorithmic method

Finally, there are algorithmic methods for generating pseudo-random numbers, such as linear congruent  or Mersenne-Twister generators .

 

Because if randomness can be used for play (video games for example), it is also very important in terms of security and cryptology. In this context, it is essential not to be able to guess the elements that were used for the generation. Because with the latter, it is possible to deduce the remainder.

Leave a Reply