A quantum random bit generator

Three Hadamards and three measurements give a random number from 0 to 7.

Beginner · 3 qubits · 3 gates · 0 two-qubit · depth 1 · reviewed November 2026

Open in the Circuit Builder

What is happening

Each qubit produces an independent fair bit. Together the three bits give a number from 0 to 7 with equal probability. On real hardware this is the principle behind quantum random number generators.

In this simulator the “randomness” comes from a seeded pseudo-random number generator, so it is repeatable, which helps with teaching but is not secure randomness.

Step by step

  1. 1. Hadamard on every qubit

    Each qubit is an independent fair coin.

  2. 2. Measure

    Reading the three bits left to right gives a binary number.

Expected result

Eight outcomes, each about 12.5% in the shot histogram.

Qubit 0 is the leftmost bit. In Qiskit, bitstrings are printed in the reverse order.

Qiskit code

from qiskit import QuantumCircuit
from math import pi

qc = QuantumCircuit(3, 3)
qc.h(0)
qc.h(1)
qc.h(2)
qc.barrier()
qc.measure(0, 0)
qc.measure(1, 1)
qc.measure(2, 2)

# Qiskit prints bit strings with qubit 0 on the RIGHT; this site writes qubit 0 on the LEFT.

Try this

  • Increase the shots to 4096 and see the counts even out.
  • Use fewer shots and see how uneven small samples look.
  • Add an X on one qubit to bias the first bit.

Gates used

Related reading

Questions

Can I use this for passwords or keys?

No. This simulator is not a source of secure randomness.