Can a Computer Ever Be Truly Random?

Computers are built on logic and rules, yet they can generate seemingly random numbers; how does this happen? Dive into the world of mathematical algorithms, radioactive decay and the mysteries of quantum physics.

St Andrews 20267 min read · 3 reads

Randomness is all around us. Just think about dice rolls, coin flips, or even choosing a card from a shuffled deck. You can easily calculate the odds, but you usually can't be certain of the outcome. Yet even when nature appears random, it often follows patterns that we can observe.

Take the toss of a coin, for example. Although we usually consider it to be a random event, if we were able to recreate the exact conditions of the flip (motion, angle, force, etc.), the coin would theoretically land on the same side every time according to classical physics. Therefore, perhaps what we call randomness is just our inability to predict the outcome of events.

So what about computers? Well, computers are logical machines - they follow mathematical rules and precise instructions. Yet if computers are fundamentally predictable, how do they generate random numbers?

The Illusion of Randomness

Early computers faced a problem: they were able to perform precise calculations, but scientists and researchers needed random numbers for experiments, statistics and simulations.

One of the earliest computer-based approaches to generating random numbers was the middle-square method invented by a Hungarian-American mathematician named John von Neumann in 1946. The concept was surprisingly simple:

  1. Start with a six-digit number: 123456
  2. Square that number: 15241383936
  3. Take the middle six digits of the twelve-digit result: 015241383936
  4. Repeat with the new number: 241383 → 058265752689 → 265752

Erin Herzstein (2021), How Computers Generate Random Numbers, Level Up Coding.Erin Herzstein (2021), How Computers Generate Random Numbers, Level Up Coding.

This method was appealing because the numbers seemed to jump around unpredictably, even though it involved nothing more than simple multiplication. However, there was an issue - some starting numbers produced very short repeating cycles, while others reached 0 and stayed there. For example, starting with "000000" gave "000000" forever. This made the middle-square method unreliable for many applications.

During the late 1940s and 1950s, researchers developed more systematic algorithms such as linear congruential generators, using a wider range of arithmetic operations to generate sequences with better statistical properties. However, the idea of using arithmetic for generating random numbers remains important today, although modern methods use much more sophisticated algorithms.

The middle-square method is an example of a pseudorandom number generator (PRNG). These are mathematical algorithms which generate a sequence of numbers that look random, even though the sequence is determined by its initial state. For example, with the middle square method, if you start with the same number as another computer, you will get the same sequence of numbers.

In all of these examples, there has been a starting value that determines the sequence of numbers generated. This number is called the seed, and it is the starting point of the mathematical process. The seed does not provide the computer with the random numbers to produce; rather, it determines the initial state from which the algorithm generates its sequence.

To generate an unpredictable sequence, a PRNG needs a seed that is difficult to guess. Some programs use the current date and time as their seed, as it provides them with an easy way to get a seed that changes every time the program is run. However, this also comes with disadvantages, as if someone knows approximately when a program is started, they might be able to guess the seed and therefore reproduce the sequence. This makes using the current date and time unsuitable for generating cryptographic keys or other security-sensitive random values.

However, in some applications, the seed does not need to be hidden or secure. An example of this is the world generation in Minecraft. When you create a new world, the game uses a world seed as an input to its terrain generation algorithms. These algorithms determine where features such as biomes, caves and structures spawn. By allowing the user to see and set the seed, Minecraft allows players to independently generate enormous, identical landscapes without sharing the world files, as long as they both have the same seed and game version.

This example shows that in some cases, the predictability of pseudorandom generators can be an advantage, especially in areas such as gaming, scientific simulations and debugging. However, different applications might require computers to generate more unpredictable random numbers, so what are some ways that computers can go beyond mathematical algorithms to produce randomness?

Harnessing Randomness from the Physical World

As we have seen, pseudorandom number generators can be useful in many applications. Yet in some cases, there is a need for a more unpredictable number generator. The problem is that computers work through logic and mathematics, as discussed earlier, so how do we break out of those limitations and generate true random numbers?

Rather than generating numbers entirely based on mathematical algorithms, computers could instead measure physical events that are unpredictable. For example, a device that detects radioactive particles could measure the time taken between two detections, and use that as a source of randomness.

This is the principle behind True Random Number Generators (TRNGs), where a computer measures a physical process to obtain fresh, unpredictable measurements. One method used by TRNGs involves measuring radioactive decay.

Radioactive isotopes have unstable nuclei that decay spontaneously, releasing particles or electromagnetic radiation. While we can predict approximately how many nuclei will decay in a large sample over a period of time, it is impossible to predict exactly when a particular nucleus will decay. This makes radioactive decay a measurable source of physical randomness.

A detector connected to a computer could detect decay events and use the intervals between detected decay events to produce binary digits (1s and 0s). It could then use the bits as a seed for a PRNG, group the bits into numbers, or run scientific models and simulations.

Nuclear Random Number Generator by M.daSilvaNuclear Random Number Generator by M.daSilva

Another TRNG method is using electronic noise to obtain randomness without the need for a radioactive source. All electronic circuits contain tiny fluctuations in current and voltage. These fluctuations can be measured, converted into digital values and used to generate random numbers.

TRNGs differ from ordinary Pseudorandom Number Generators as they obtain fresh uncertainty from physical processes. These physical processes are called entropy sources, as the unpredictability from physical processes is measured and then used to generate random numbers.

However, are these physical events genuinely random, or simply impossible for us to predict, and if a coin flip's outcome follows physical laws, could radioactive decay also follow hidden rules?

Is Anything Truly Random?

As discussed at the beginning, although coin flips appear random, their outcomes are determined by certain initial conditions. If we knew those exact conditions, we could theoretically predict the results of a coin flip every time. So does that mean that unpredictability simply stems from incomplete information, and could the same principle apply to everything in the universe?

Quantum mechanics, however, describes many events using probabilities. For example, we can predict the probability of radioactive decay, but not the exact time an individual nucleus will decay. Under standard quantum interpretations, this uncertainty is fundamental rather than determined by conditions. However, other interpretations suggest that the universe could be deterministic, with outcomes governed by underlying physical laws.

This brings us back to our original question: can a computer ever truly be random? While computers can generate seemingly random numbers using mathematical algorithms, they can also measure randomness in nature without necessarily creating it. Perhaps the question isn't whether computers can generate randomness, but whether randomness exists in the universe at all...

Bibliography

Arobelidze, Amiran. "Random Number Generator: How Do Computers Generate Random Numbers?" freeCodeCamp, 26 Oct. 2020, www.freecodecamp.org/news/random-number-generator/.

Carnegie Mellon University. Lecture 9: Pseudo-Random Number Generation. 2015, www.cs.cmu.edu/~15110-n15/lectures/unit09-1-PRNG.pdf. Lecture.

Heiss, Andrew. "Generating Universes Within Universes with a Single Seed." Andrew Heiss, 13 Apr. 2026, www.andrewheiss.com/blog/2026/04/13/seeds-predetermined-universes/.

Herzstein, Eric. "How Computers Generate Random Numbers." Level Up Coding, 7 Jan. 2021, levelup.gitconnected.com/how-do-computers-generate-random-numbers-a72be65877f6.

"How Can a Totally Logical Machine Like a Computer Generate a Random Number?" HowStuffWorks, 8 Aug. 2001, computer.howstuffworks.com/question697.htm.

Reader discussion

Join the conversation.

0 contributions

No comments yet. Start the discussion.

Deep Dive

Written by students at Eton.
Read by anyone curious.

Your cookie preferences

We use essential cookies to run this website. With your permission, we also use analytics cookies to understand how visitors use the site.