About Pi from Darts
Throw darts at random at a square board with a circle drawn inside it. The circle covers π/4 of the square (about 78.5%), so about that share of the darts land inside, and 4 × inside ÷ thrown is an estimate of π. Press THROW, pick a speed, and watch the estimate and the chart. The highlighted digits are the ones it has right so far.
BUFFON'S NEEDLE does it another way: drop needles on a floor of boards. A needle no longer than the gap between the cracks crosses a crack with a chance of 2 × length ÷ (π × gap), so counting crossings estimates π too. Each run uses a new random seed; type one in (and tick "Same seed") to repeat a run exactly.
THE STORY
Archimedes, in the 3rd century BC, trapped π between the perimeters of polygons with 96 sides drawn inside and outside a circle, showing it lies between 3 10/71 and 3 1/7 (that's 22/7).
In 1733 Georges-Louis Leclerc, Comte de Buffon, asked how often a needle dropped on a floor of boards would land across a crack. He published the answer in 1777: π turns up in it, so needles can measure π. In 1901 the Italian mathematician Mario Lazzarini said he had dropped a needle 3,408 times and got 355/113, right to six decimal places. That is far better than chance makes likely, and it's widely thought he stopped at the count that gave the answer he wanted.
Using random numbers to work things out became a serious tool at Los Alamos in the 1940s, where Stanisław Ulam and John von Neumann used it on problems too hard to solve on paper. It was code-named the Monte Carlo method, after the casino in Monaco.
WHY IT'S SO SLOW
The error shrinks only like 1/√n: after n darts the estimate typically wobbles by about 1.64/√n. You need around 100,000 darts to expect two right decimal places and around 10 million for three: each extra place needs about 100 times as many. The shaded band on the chart is that expected wobble (one standard deviation), and on the ERROR view it's the straight dashed line sloping down.
HOW IT WORKS
Darts come from a seeded sfc32 random generator, seeded from your browser's crypto source, so the statistics are honest. A needle's angle is chosen by picking random points in a half-circle until one lands inside, so π isn't used to make the estimate of π. As they pile up, the picture shows the darts as smaller and smaller dots and, after the first 10,000, only some of the needles; every one is counted. This is a port of a Python script, pi-monte-carlo.py, which threw its darts at a quarter of the square: the same odds.
FURTHER WATCHING AND READING