hcoin to πthe paper

a coin. a stopping rule. a very slow calculator.

Find π.
Flip a coin.

Flip until heads first outnumber tails.
Save the fraction of heads. Start over.
Average those fractions, then multiply by 4.

01 try one run

your turn
0heads
0tails

A tie doesn’t count. Heads need the lead.

Each click is a random flip. The coin is a visual,
not a physics simulation.

02 let your browser do the work

One run can take many flips. 1 lakh runs = 100,000 fresh starts.

seed & flip limit

Keep the same settings to reproduce a result. Limit: 1 million runs per experiment. You can start again as often as you like.

ready when you areπ = 3.14159…
—your estimate
0runs included
0individual flips
0hit the limit

Your coin flips will draw this line.

teal: your estimate gold: π, for comparison only

The answer won’t land exactly on π. That’s part of the experiment.

The patient-coin problem.

Some runs take a very, very long time. We put a limit on each one. If it hasn’t finished, we include a range for its eventual result instead of throwing it away.

the maths, without the mystery

At the first heads lead, heads exceed tails by exactly one. After n flips, the head fraction is ½ + 1/(2n). If a run hits its limit k, its eventual fraction lies between ½ and ½ + 1/[2(k+1)].

The displayed estimate uses the lower ends of those ranges. The unfinished-run range is separate from the approximate 95% sampling interval. A small sample, an early stop, or a very low flip limit can make the estimate uninformative. This is a numerical illustration of a theorem, not a proof.

Everything runs locally in a background worker. Bulk runs use a seeded Mulberry32 pseudorandom generator, not the NumPy generator used for our original post. Different generators produce different samples.

read the simulation source ↓