Abhinav's Blog

The Illusion of Randomness: From Python to Quantum

Every time you call a random function in Python, you think you’re getting a truly random number. In reality, it is far from what’s actually happening under the hood.

The basic idea is simple: Python does not know randomness. It is deterministic, just like every other language.

Here is a short story on randomness in computers, its impact, and a glimpse into how quantum mechanics changes the picture.


The Fundamental Logic

Let’s look at things from a very rudimentary view.

Now, the way any function works is by following a strict path:

Input > Computation > Output

To get a random result, we have to figure out: what input do we give, and what computation do we perform?

The computation part must be deterministic. The math or algorithm inside the function cannot be "random" as it is a sequence of mathematical steps to be executed by the program. Since the algorithm is fixed, the only parameter you can truly control is the input.


How Languages "Simulate" Randomness

How do you give random inputs to a function? In the simplest terms, something that changes with time can be thought of as random.

What changes with time? Time itself.

That is what Python really uses: your system’s time as an input seed for random.randint(). With a random input (system time) and a specific algorithm (Mersenne Twister), Python generates a pseudo-random output.

Note: Most languages like Python use system time or OS-specific randomness from an Entropy Pool Read More Here

The Proof of Determinism

You can actually check this by running the code below. If you pass random.seed(42), the input seed is fixed, and the output remains exactly the same every single time.

Python

import random
import time

# If I fix the seed, the result is predictable
random.seed(67)
print(random.randint(1, 100))
# This will always print the same number.

Computer Randomness vs. True Entropy

Computers, by design, are built to be deterministic. They are logical machines made of binary digits; all they know is 0 or 1. They cannot "add" randomness; they can only simulate it through an algorithm.

The only way to achieve true randomness is through Entropy a measure of randomness or disorder.

How to make a True Random Number Generator?

A famous example of this is Cloudflare’s "Wall of Entropy." It is a True Random Number Generator (TRNG) that uses:

The camera captures the movement of the lava inside the lamps and people who pass in front of it to generate random data that is used to make cryptographic keys. Because that movement is physical, complex, and unpredictable, it provides the security that predictable code cannot.


The Quantum Shift and Quantum Random Number Generators

Classical “true” random number generators still rely on physical processes: noise, chaos, thermal effects, or messy real-world systems like lava lamps. These are unpredictable in practice, but are also too complex to model.

Quantum systems are different.

The Quantum State is non-deterministic, which means if you observe a photon; it is in a state of Superposition (spinning Up and Down at the same time). The true position can only be known once you measure it.

When you measure the photon, it is forced to pick one definite outcome. There is no hidden variable or secret state deciding it.

Quantum Random Number Generators (QRNGs) exploit this principle. They generate randomness directly from measuring quantum systems like photons, not from classical algorithms or physical chaos.

Nature is forced to choose.

This randomness is intrinsic and fundamentally unpredictable.


In Python, randomness is a math problem. In the real world, it is a fundamental truth. Perhaps that is the beauty of computing. We use deterministic machines, built on zeros and ones, to try and capture the infinite chaos of the universe. Next time you call random.randint(), remember: you aren't invoking chaos. You are just simulating it. If you enjoyed this blog, consider following me on X: abhinavv008