Back to news

In Folha, Viana comments: ‘Randomness and the computer’

Reproduction of Marcelo Viana’s column in Folha.

Throughout history, we have developed various methods to produce random, i.e. unpredictable, results: dice, coins, roulette wheels and many others. Games of chance would not exist without this. In other games, such as cards, although the rules are totally deterministic, there is still a crucial element of randomness – the initial state of the deck – which is achieved by shuffling the cards.

Nowadays, there are many other practical applications for random values, so it’s important that we can produce them quickly and easily using computers. That’s where things get complicated, because computers don’t throw dice or toss coins. All they do is execute a sequence of predetermined instructions, where there is no room for randomness. The way out of this difficulty has been to work with pseudo-random numbers, which look random, but aren’t really.

In the 1980s, when personal computers became a reality (everything I earned from tutoring I spent on buying an Apple IIe, a consumer dream!), everyone who had one programmed in Microsoft Basic. It came with an RND function that generated random numbers. Supposedly.

What she was actually doing was producing a sequence of numbers x1, x2, x3, … using the formula xn+1 = remainder of the division of (1140671485 times xn + 12820163) by 16777216. To start the calculation, you need to choose the value of the “seed” x0, from which the numbers in the sequence are successively obtained using this formula. In the first versions of Basic, the seed was always x0 = 0, but this had an embarrassing effect: RND always produced exactly the same sequence of numbers! The first time, it might surprise you, but from then on it was predictable.

To remedy this, later versions of Basic had a RANDOMIZE command, which changed the seed based on the time set on the computer’s clock. More advanced languages went further, using other hardware parameters (such as mouse movement), or even physical phenomena external to the computer, to introduce more unpredictability into the calculation. The results are good enough for most applications, but they are still cheating: traditional computers, based on the laws of classical physics, cannot generate genuinely random numbers.

The revolution in physics at the beginning of the 20th century radically changed the outlook in this area. In quantum mechanics, experimental measurements are not predetermined. Whenever a photon is sent towards a barrier with two identical slits, the chance of it passing through each of them is 50%, just as if the photon were a coin flip. Similarly, whenever we measure the spin of an electron, the result can be either +1/2 or -1/2, again with equal probabilities.

Read it in full on Folha’s website.