Theory & derivation
In 1777 Georges-Louis Leclerc, Comte de Buffon, posed this
question: if you drop a needle of length L onto a
floor ruled with parallel lines spaced d apart (with
L ≤ d), what is the probability the needle crosses a
line?
Let x be the distance from the needle's centre to the
nearest line (uniform on [0, d/2]) and
θ its angle (uniform on [0, π/2]). The
needle crosses when x ≤ (L/2)·sin θ. Integrating over
both uniform variables gives the crossing probability
P = 2L / (π·d).
Rearranging, π = 2L / (P·d). We estimate
P by the observed fraction
crossings / N, so
π ≈ 2·L·N / (d·crossings). By the law of large
numbers the observed fraction converges to the true probability,
and the estimate of π converges to 3.14159… — a striking way to
compute π using only random geometry.