Drop needles on a floor of planks and count how many land across a crack. The answer hides π.
Drop a few hundred needles first. Does the fraction that cross settle down? What does it settle near?
For a needle as long as a plank is wide, the chance of crossing a crack is 2/π, about 0.6366. So π ≈ 2 ÷ (the fraction that cross). With a shorter needle of length L, the chance is 2L/π.
Here is a way to see it without calculus, due to Joseph-Émile Barbier in 1860. Think about the average number of cracks a needle crosses. Bend the needle and that average doesn't change: each small piece of it crosses cracks just as often as before. So the average depends only on the needle's length. Now bend a needle into a circle whose diameter is exactly one plank. However it lands, a circle that wide always touches cracks exactly 2 times. Its length is π, so a length of π crosses 2 cracks on average, and a length of 1 crosses 2/π.
Each needle gets a random center, anywhere on the floor with every spot equally likely. For its direction, the computer picks a random point in a square around the center and throws it away unless it lands inside the circle that fits in the square; then the needle points toward that point. Every direction is equally likely, and the computer never uses π to aim the needles, so the π that comes out is a real discovery, not one we sneaked in.
The random numbers come from the browser's built-in generator, which produces numbers that pass statistical tests for randomness, though they come from a formula rather than from the physical world.
Georges-Louis Leclerc, Comte de Buffon, asked this question in 1733 and published the answer in 1777. It was one of the first problems in geometric probability. In 1901 the Italian mathematician Mario Lazzarini reported 3,408 tosses that gave π ≈ 355/113 = 3.1415929, accurate to six decimal places. That result is almost certainly too good to be true: a fair experiment that size would usually miss by around 0.03.