Buffon’s needle

Estimate π from seeded needle drops and inspect the final uncertainty interval.

About this tool

This is Buffon’s short-needle model: a straight needle of length L falls among parallel lines spaced d apart, with 0 < L ≤ d. Both lengths are in millimetres. The position within a line period and the direction are uniform. Scaling L and d together leaves the probabilities unchanged. Longer needles require another formula and are rejected.

Each throw uses a centre phase y ∈ [0,d) and an angle θ ∈ [0,π). It hits when min(y,d−y) ≤ (L/2)|sin θ|. Touching either line counts symmetrically, and each needle contributes at most one hit. The model probability is p = 2L/(πd). After n throws and K hits, the observed rate is K/n and the estimate is π̂ = 2(L/d)n/K. With no hits, there is no finite π estimate; a dash is shown instead of zero.

The seed fixes a reproducible sequence. The 32-bit generator uses s ← (1664525s + 1013904223) mod 2³² and u = (s + 0.5)/2³². Each needle consumes exactly two values, first for y and then for θ. It is a teaching generator, not a source of cryptographic randomness. The display consumes no random values: horizontal placement depends only on the throw index, and vertical placement changes y only by whole multiples of d. The floor shows the last 200 needles at equal x/y scale. Counts and the linear convergence plot use every throw, including large early estimates.

Start or resume displays about 250 throws per second. A frame accounts for at most 0.1 seconds; pausing, hiding or leaving the tool discards outstanding display time. One needle advances exactly once. Editing any input clears the previous run; Reset keeps the inputs. Returning within the app preserves the run, paused. A full reload restores only valid inputs.

Only at the planned final count does the tool show a Wilson 95% interval [pL,pU] for the hit rate, using z = 1.959963984540054. With p̂ = K/n, its centre is (p̂ + z²/(2n))/(1 + z²/n) and its half-width is z√(p̂(1−p̂)/n + z²/(4n²))/(1 + z²/n). The corresponding π interval is [2(L/d)/pU, 2(L/d)/pL]. When pL = 0, the upper bound is unbounded; this is an interval bound, not an available point estimate. Nominal 95% coverage does not guarantee that every seeded run contains π, and this is not a continuously valid interval for repeatedly choosing when to stop.

Sources: Treibergs, Integral Geometry, slides 20–21 derives the short-needle probability and estimator; extending its L < d statement to L = d follows here by continuity and zero-probability boundary positions. NIST: Binomial Proportions describes the Wilson interval. Its monotone transformation to a π interval and reporting only at the planned end are choices of this tool.