Apex › Storage & databases

Estimating π by throwing darts (Monte Carlo)

Estimate a quantity by random sampling. Throw darts at a unit square with a quarter-circle inscribed: the fraction landing inside is the area ratio π/4, so four times it estimates π. The average converges (law of large numbers) and the error shrinks like 1/√N (central limit theorem) — quadruple the darts to halve the error — a rate independent of dimension, which is why Monte Carlo beats grids for high-dimensional integrals. Verified in node (σ halves per 4× samples: 0.164, 0.082, 0.041… → 3.14159). Produce both truths: pick N and throw 140 independent runs — the answers scatter (it’s random), and stepping N up ×4 only halves the spread (it’s slow — 100× the darts buys one more digit).

More in Storage & databases