Updated
In this lesson
Wide tables, equations, and code scroll sideways. Swipe, or Tab to focus them and use the left and right arrow keys.
Buffon’s needle
You will learn: Relate a geometric crossing experiment to its angle and length assumptions.
Start with: Uniform distribution · Events and probability
In 1777, Georges-Louis Leclerc, Comte de Buffon asked: if you drop a needle of length onto a floor with parallel lines spaced apart (), what is the probability the needle crosses a line?
The answer connects a purely geometric experiment to π:
Rearranging, you get a Monte Carlo estimator for π:
Here needle centers are uniform relative to the parallel lines, orientations are uniform on [0,π), and drops are independent. N counts all drops and C counts crossings. The formula assumes ℓ ≤ d. With C=0 the ratio is undefined; the demo reports this explicitly.
Make a prediction
If you halve the needle length while keeping the line spacing fixed, what happens to the expected crossing count?
Explore the answer
It halves, since the crossing probability is proportional to needle length for ℓ≤d. Fewer crossings generally make the estimate of π less precise at the same number of drops.
How uncertain is this estimate?
Nominal 95% interval for π: [2.896, 3.294]. This transforms a Wilson interval for the crossing probability by reversing its endpoints. It is an approximate repeated-sampling procedure; π itself is fixed.
57 of 60 intervals include π; 0 repeats have no crossings and an undefined point estimate. Each repeat uses 500 independent drops. Solid intervals include π; dashed intervals miss it. The plot stops at 8: 0 intervals extend above the display, including unbounded ones.
Read the exact results for all 60 repeats
| Repeat | Crossings | Estimate | 95% interval | Includes π |
|---|---|---|---|---|
| 1 | 309 | 3.236 | 3.032 to 3.480 | Yes |
| 2 | 309 | 3.236 | 3.032 to 3.480 | Yes |
| 3 | 323 | 3.096 | 2.913 to 3.316 | Yes |
| 4 | 316 | 3.165 | 2.971 to 3.396 | Yes |
| 5 | 310 | 3.226 | 3.024 to 3.468 | Yes |
| 6 | 328 | 3.049 | 2.872 to 3.261 | Yes |
| 7 | 321 | 3.115 | 2.929 to 3.339 | Yes |
| 8 | 303 | 3.300 | 3.087 to 3.555 | Yes |
| 9 | 327 | 3.058 | 2.880 to 3.272 | Yes |
| 10 | 319 | 3.135 | 2.946 to 3.362 | Yes |
| 11 | 303 | 3.300 | 3.087 to 3.555 | Yes |
| 12 | 317 | 3.155 | 2.963 to 3.385 | Yes |
| 13 | 325 | 3.077 | 2.896 to 3.294 | Yes |
| 14 | 323 | 3.096 | 2.913 to 3.316 | Yes |
| 15 | 331 | 3.021 | 2.849 to 3.229 | Yes |
| 16 | 310 | 3.226 | 3.024 to 3.468 | Yes |
| 17 | 344 | 2.907 | 2.751 to 3.096 | No |
| 18 | 315 | 3.175 | 2.980 to 3.408 | Yes |
| 19 | 330 | 3.030 | 2.856 to 3.239 | Yes |
| 20 | 311 | 3.215 | 3.015 to 3.456 | Yes |
| 21 | 322 | 3.106 | 2.921 to 3.327 | Yes |
| 22 | 313 | 3.195 | 2.997 to 3.432 | Yes |
| 23 | 322 | 3.106 | 2.921 to 3.327 | Yes |
| 24 | 312 | 3.205 | 3.006 to 3.444 | Yes |
| 25 | 319 | 3.135 | 2.946 to 3.362 | Yes |
| 26 | 312 | 3.205 | 3.006 to 3.444 | Yes |
| 27 | 320 | 3.125 | 2.937 to 3.350 | Yes |
| 28 | 315 | 3.175 | 2.980 to 3.408 | Yes |
| 29 | 321 | 3.115 | 2.929 to 3.339 | Yes |
| 30 | 322 | 3.106 | 2.921 to 3.327 | Yes |
| 31 | 308 | 3.247 | 3.041 to 3.493 | Yes |
| 32 | 311 | 3.215 | 3.015 to 3.456 | Yes |
| 33 | 296 | 3.378 | 3.153 to 3.647 | No |
| 34 | 322 | 3.106 | 2.921 to 3.327 | Yes |
| 35 | 317 | 3.155 | 2.963 to 3.385 | Yes |
| 36 | 303 | 3.300 | 3.087 to 3.555 | Yes |
| 37 | 310 | 3.226 | 3.024 to 3.468 | Yes |
| 38 | 333 | 3.003 | 2.833 to 3.208 | Yes |
| 39 | 304 | 3.289 | 3.078 to 3.543 | Yes |
| 40 | 318 | 3.145 | 2.954 to 3.373 | Yes |
| 41 | 321 | 3.115 | 2.929 to 3.339 | Yes |
| 42 | 318 | 3.145 | 2.954 to 3.373 | Yes |
| 43 | 319 | 3.135 | 2.946 to 3.362 | Yes |
| 44 | 323 | 3.096 | 2.913 to 3.316 | Yes |
| 45 | 313 | 3.195 | 2.997 to 3.432 | Yes |
| 46 | 321 | 3.115 | 2.929 to 3.339 | Yes |
| 47 | 343 | 2.915 | 2.758 to 3.105 | No |
| 48 | 312 | 3.205 | 3.006 to 3.444 | Yes |
| 49 | 332 | 3.012 | 2.841 to 3.218 | Yes |
| 50 | 327 | 3.058 | 2.880 to 3.272 | Yes |
| 51 | 322 | 3.106 | 2.921 to 3.327 | Yes |
| 52 | 311 | 3.215 | 3.015 to 3.456 | Yes |
| 53 | 335 | 2.985 | 2.818 to 3.187 | Yes |
| 54 | 318 | 3.145 | 2.954 to 3.373 | Yes |
| 55 | 312 | 3.205 | 3.006 to 3.444 | Yes |
| 56 | 332 | 3.012 | 2.841 to 3.218 | Yes |
| 57 | 314 | 3.185 | 2.988 to 3.420 | Yes |
| 58 | 309 | 3.236 | 3.032 to 3.480 | Yes |
| 59 | 315 | 3.175 | 2.980 to 3.408 | Yes |
| 60 | 308 | 3.247 | 3.041 to 3.493 | Yes |
What to notice
- The estimate converges slowly. After 500 needles the estimate might still be off by 0.02–0.1. Monte Carlo estimators for π converge at rate — you need 100× more needles to gain one decimal place.
- Solid crosses, dashed misses. A needle crosses a line when its centre is within of the nearest line, where θ is the needle’s angle.
- Resample to see a new realisation and how much the estimate varies from run to run.
Why π appears
The crossing probability comes from integrating over all possible needle positions and angles. The integral of over evaluates to 2, and dividing by the normalising constant is what injects π into the formula. The geometry forces trigonometry, and trigonometry carries π.
From geometry to probability
Let U be the distance from the center to the nearest line. Uniform placement makes U uniform on [0,d/2]. At angle θ, crossing requires U≤(ℓ/2)|sin θ|. Since ℓ≤d, this gives conditional probability (ℓ/d)|sin θ|. Averaging over uniform θ in [0,π) gives:
Longer needles can cross multiple lines, and the conditional probability above can exceed one before being capped. That is why this experiment restricts ℓ/d to at most one; substituting longer lengths into the short-needle formula is invalid.
An interval, not extra decimal places
Each independent drop contributes a Bernoulli crossing indicator, so C has a binomial distribution. The demo constructs a nominal 95% Wilson interval [p_low,p_high] for its success probability and transforms it to [2ℓ/(d·p_high), 2ℓ/(d·p_low)]. The endpoint order reverses because the reciprocal decreases.
When C=0, the point estimate is undefined and the upper interval endpoint is unbounded. Those runs remain in the repeated-experiment display and coverage denominator. The finite plot clips large interval endpoints only for drawing; the table preserves their values.
Wilson coverage is approximate and varies with sample size and crossing probability. The fraction of 60 displayed intervals containing π is itself noisy; it need not be 95%. Increasing N reduces typical sampling error at an asymptotic 1/√N rate, but cannot guarantee that the next estimate improves. The reciprocal estimator also has finite-sample bias.
Make a prediction
Does an interval containing 3.14159 mean this run established five accurate decimal places?
Explore the answer
No. Read the whole interval width. Displayed digits are formatting, while repeated sampling reveals how much estimates fluctuate. Quadrupling N roughly halves typical error, rather than adding a fixed number of correct digits.
Reference
NIST: confidence intervals for a binomial proportion describes Wilson score inversion and distinguishes approximate intervals from exact binomial procedures. The reciprocal transformation above applies it to this experiment.