|q⟩ Bad Qubits

beginner · Programming · Mini-Projects: Coin Flips, RNG & Bell Tests

Project: A Quantum Coin Flip

Imagine flipping a coin. A classical coin gives heads or tails based on physics you cannot fully control — the outcome looks random but is technically deterministic given exact initial conditions. A quantum coin flip is different: the randomness is not due to ignorance. It is a direct consequence of quantum measurement, and it is provably irreducible.

The idea

A qubit starts in the definite state 0|0\rangle. A Hadamard gate HH transforms it into an equal superposition:

H0=12(0+1).H|0\rangle = \frac{1}{\sqrt{2}}\big(|0\rangle + |1\rangle\big).

The two amplitudes are each 12\tfrac{1}{\sqrt{2}}. By the Born rule, measuring this state yields 0 with probability 122=12\left|\tfrac{1}{\sqrt{2}}\right|^2 = \tfrac{1}{2} and 1 with the same probability — a perfect 50/50 coin flip.

There is no hidden variable steering the result. Before you measure, the qubit genuinely carries both possibilities at once. After you measure, the state collapses to whichever outcome was observed and that outcome is irreversible.

Why quantum randomness is different

Classical pseudorandom number generators (PRNGs) are deterministic algorithms seeded by some initial value. Given the same seed, a PRNG always produces the same sequence — so the randomness is only apparent. Quantum measurement produces outcomes that cannot be explained by any local hidden variable; this is the content of Bell's theorem, which rules out local hidden-variable theories. Hardware random number generators used in cryptography increasingly exploit this property.

Try it

Build the quantum coin flip: apply a Hadamard to qubit 0 and then measure it. The grader checks that your circuit produces the 50/50 distribution — both outcomes should occur with probability 12\tfrac{1}{2}.

Run your code to see the quantum state.

After running, open the Probabilities panel. You should see two equal bars at 0.50.5 for 0 and 1. That is your quantum coin, balanced by the laws of quantum mechanics rather than by luck.

Sign in on the full site to ask questions and join the discussion.