Presets
Playback
Method
Speed
Method parameters
Replicate experiment
Camera
Layers
Quality
Model check
The science
Four ways to get pi from random numbers
Each method is a Bernoulli trial with success probability p that contains pi, so k successes in n trials give an estimate. Darts: a uniform point in the unit square lands in the quarter disc with p = π/4, so π̂ = 4k/n. Buffon: a needle of length l dropped on lines d = 1 apart (l ≤ d) crosses one with p = 2l/(πd), so π̂ = 2ln/k. Coprime pairs: two random integers share no factor with probability 6/π2, so π̂ = √(6n/k). Ball in a cube: the unit ball fills π/6 of the cube [−1,1]3, so π̂ = 6k/n.
How fast does the error shrink?
The count k is binomial, so σ(p̂) = √(p(1−p)/n) and the delta method gives σ(π̂) = |dπ/dp| √(p(1−p)/n). Every method therefore has error ∝ 1/√n: ten times more accuracy costs a hundred times more samples (the dashed envelope and the slope-−1/2 line in the graphs). Methods differ only in the constant: needles with l = 0.8 are noisier than darts, and the ball estimate is noisier still.
Quasi-random points
The Halton sequence (radical inverses in bases 2, 3, 5) fills space more evenly than random points. Its error for a smooth-edged region like a disc falls like (log n)d/n, much faster than 1/√n, but there is no honest confidence interval from a single run, which is why the envelope is not drawn for it.
Honest simplifications
The generator is a 32-bit pseudo-random sequence (mulberry32), not true randomness. The coprime method has a small systematic bias of order log M / M for integers limited to 1..M; with M = 106 it is negligible. Buffon's estimator 2ln/k is slightly biased for small k (it divides by a random count). Nothing here is a good way to compute pi: the point is the statistics.
Model checks in this page
(1) 400 replicates of 2000 darts have the predicted standard deviation; (2) the same for Buffon's needle with the delta-method value; (3) an exhaustive count of coprime pairs below 1500 reproduces pi to well under 1 %; (4) Halton darts beat the pseudo-random one-sigma error at n = 100000.