Quantum Lottery

A playful simulation of how randomness + a measurement choice can decide a final YES/NO outcome — like flipping a coin, but with a Stern–Gerlach-style projection hiding underneath.

Main outcome
Live ⟨p⟩: .
Sᵧ: — ⟨p⟩: — N: — Anim: —

Physics and what this code does

Ready.

Stern–Gerlach idea. A spin-1/2 particle passing through a magnetic-field gradient splits into two discrete outcomes: UP or DOWN along the chosen axis. Measuring spin is therefore a binary quantum measurement.

Quantum state. Each trial generates a random spin state ψ = (ψ1, ψ2), a two-component complex vector. The state is normalized so that |ψ1|² + |ψ2|² = 1.

Measurement basis (Sy). Spin “UP” and “DOWN” along the y-axis are represented by the vectors
UP = (1, i) / √2 ,    DOWN = (1, −i) / √2
The ±i is a relative phase that defines orientation along the y-direction.

Probability (Born rule). If ψ is the measurement vector (UP or DOWN), the probability is p = | ψ* · ψ |²
where ψ* is the complex conjugate of φ

Quantum lottery. Repeating this for many random ψ states produces a running average probability ⟨p⟩. This evolving ⟨p⟩ is mapped to a visible YES / NO outcome — like a coin flip driven by quantum spin.

Average ⟨p⟩
Std(p)
Spread of per-trial probabilities
Decision
Threshold at 0.5

Visuals