Project 02 · Ladder 1 · Beginner
Quantum Dice Roller: three qubits, one perfectly fair die
How it works
- Three qubits give eight outcomes, 000 to 111, all equally likely.
- Six of them map to the six faces. The two left over (red) are rolled again.
- That's rejection sampling: every face stays at one in six, where the % 6 shortcut loads 1 and 2.
Three qubits, eight possible worlds, one perfectly fair die. And a bug that catches professionals out.
- Level
- Beginner
- Hours
- 3 to 5
- Automated tests
- 16
- Ships to
- GitHub
What you build
Quantum Dice Roller in Python and Qiskit
You've flipped a quantum coin. Now go multi-qubit. You'll build a die from three qubits, discover that 3 qubits give 8 outcomes but a die has only 6 faces, and solve it the way professionals do, with rejection sampling. Then you'll prove, with your own tests and your own chart, that the "obvious" shortcut is quietly loaded.
Three qubits give you 8 possible outcomes. Google's 105-qubit Willow chip has 2¹⁰⁵: about 40 million trillion trillion. You make the same move at small scale: put several qubits into superposition at once, sample them, and turn raw bit strings into a die that works for any number of sides.
Spotting, measuring and fixing a subtle bias like this is exactly the kind of story that lands in an interview.
The quantum ideas inside
- Multi-qubit superposition
- Bit strings
- Rejection sampling
- Modulo bias
- Chi-square tests
New to Qiskit? Run your first circuit free, or warm up with the free Qiskit tutorials.
Real output · Project 02Qiskit Aer simulator
python quantum_dice.py --rolls 600 --seed 7 --plot dice_results.png
A 6-sided die needs 3 qubits (8 outcomes, 75% kept):
┌───┐┌─┐
q_0: ┤ H ├┤M├──────
├───┤└╥┘┌─┐
q_1: ┤ H ├─╫─┤M├───
├───┤ ║ └╥┘┌─┐
q_2: ┤ H ├─╫──╫─┤M├
└───┘ ║ ║ └╥┘
c: 3/══════╩══╩══╩═
0 1 2
First 20 quantum rolls: 3 4 6 4 1 6 4 5 1 5 5 5 4 2 6 2 5 6 5 3
Quantum face counts: {1: 111, 2: 75, 3: 108, 4: 105, 5: 103, 6: 98}
Classical face counts: {1: 107, 2: 107, 3: 93, 4: 99, 5: 109, 6: 85}
Chi-square: 8.48 (critical value at 0.1%: 20.75) -> fair
Chart saved to dice_results.png
By the end
What you walk away with
- a fair quantum d6, and a d4, d10 and d20 from the same code
- a chart that catches the loaded
% 6shortcut red-handed - 16 automated tests
- one extension that is yours alone
- a public GitHub repo, a portfolio paragraph and a LinkedIn post
Where it sits
Ladder 1: Beginner
BeginnerLadder 1
Quantum Coin Flip
One qubit, proven fair with real statistics.
Quantum Dice Roller
Catch a loaded die red-handed.
Quantum Random Number Generator
Build it, then try to break it.
Quantum Password Generator
Its strength, measured in bits.
Your first circuit is 10 minutes away
Stop watching quantum. Start shipping it.
$0 today. 7 days free, then $7.99 a week or $190 a year. Cancel any time.