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 on the throw index and available view, and vertical placement changes y only by whole multiples of d. The floor shows the last 200 needles at equal x/y scale. Red, thicker needles touch a line; blue, thinner needles miss. The dashed line marks π. Counts and the linear convergence plot use every throw, including large early estimates.
Start switches to Pause during playback; Resume continues the same run. After completion, Start begins a new run with the same inputs. With Animation enabled, about 250 throws per second are shown; with it disabled, Start finishes the planned run immediately. Settings contains Animation and the reproducible seed. One needle advances exactly once. Inputs redraw an empty experiment automatically without sampling. Reset keeps inputs and clears the experiment. Raw inputs, including unfinished numbers, survive navigation and reload; samples and histories do not. Hiding pauses playback and discards outstanding display time. The charts use the available space, and the convergence axis follows the number of throws already observed; all history and early outliers remain included.
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.