|q⟩ Bad Qubits

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

Project: A Biased Coin

The previous lesson built a fair coin: apply HH to 0|0\rangle, measure, and each outcome appears with probability 12\tfrac{1}{2}. But what if you want a coin that lands heads 75% of the time? Adjusting the bias requires a different tool — a rotation gate.

From 50/50 to any split

Every single-qubit state can be parameterised as

ψ=cos ⁣θ20+sin ⁣θ21,|\psi\rangle = \cos\!\tfrac{\theta}{2}\,|0\rangle + \sin\!\tfrac{\theta}{2}\,|1\rangle,

where θ[0,π]\theta \in [0, \pi] controls the balance between the two amplitudes (up to an overall phase we can ignore here). The Ry(θ)R_y(\theta) gate rotates the Bloch vector by angle θ\theta around the yy-axis, starting from 0|0\rangle at the north pole:

Ry(θ)0=cos ⁣θ20+sin ⁣θ21.R_y(\theta)|0\rangle = \cos\!\tfrac{\theta}{2}\,|0\rangle + \sin\!\tfrac{\theta}{2}\,|1\rangle.

By the Born rule, the probability of measuring 1 after this rotation is

P(1)=sin ⁣θ22=sin2 ⁣θ2.P(1) = \left|\sin\!\tfrac{\theta}{2}\right|^2 = \sin^2\!\tfrac{\theta}{2}.

Setting θ=π2\theta = \tfrac{\pi}{2} recovers the Hadamard result: sin2 ⁣π4=12\sin^2\!\tfrac{\pi}{4} = \tfrac{1}{2}.

Choosing the angle for a 75/25 coin

We want P(1)=14P(1) = \tfrac{1}{4}. Working backwards:

sin2 ⁣θ2=14    sin ⁣θ2=12    θ2=π6    θ=π3.\sin^2\!\tfrac{\theta}{2} = \tfrac{1}{4} \;\Longrightarrow\; \sin\!\tfrac{\theta}{2} = \tfrac{1}{2} \;\Longrightarrow\; \tfrac{\theta}{2} = \tfrac{\pi}{6} \;\Longrightarrow\; \theta = \tfrac{\pi}{3}.

After Ry ⁣(π3)R_y\!\left(\tfrac{\pi}{3}\right) the state is

Ry ⁣(π3)0=320+121,R_y\!\left(\tfrac{\pi}{3}\right)|0\rangle = \frac{\sqrt{3}}{2}\,|0\rangle + \frac{1}{2}\,|1\rangle,

giving P(0)=(32)2=34P(0) = \left(\tfrac{\sqrt{3}}{2}\right)^2 = \tfrac{3}{4} and P(1)=(12)2=14P(1) = \left(\tfrac{1}{2}\right)^2 = \tfrac{1}{4}.

Try it

Build a circuit that produces a biased coin landing on 1 with probability 14\tfrac{1}{4} (and on 0 with probability 34\tfrac{3}{4}). Apply the correctly tuned RyR_y rotation to qubit 0 and then measure. The grader compares the probability distribution, so the angle must be right.

Run your code to see the quantum state.

After running, open the Probabilities panel. The bar for 0 should be at 0.750.75 and the bar for 1 at 0.250.25 — a 3:1 coin controlled by a single rotation angle.

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