Afterglowscreensavers

Monte Carlo π Estimation Screensaver

The Monte Carlo π Estimation screensaver scatters real random points into a square, using the fraction landing inside its circle to converge on a genuine running estimate of π. It is free, runs in your browser, and ESC exits.

Live preview

Monte Carlo π Estimation screensaver — Real random darts, converging on the value of π.

Press ESC to leave fullscreen. Settings are saved in your browser only.

How the Monte Carlo π Estimation screensaver works

The saver drops a real random point into a square every frame, checking whether it also falls inside the circle inscribed within that square.

The real running ratio of points-inside-circle to total-points-thrown is multiplied by four, which converges toward the true value of π.

A live readout tracks this real estimate and its error against the true value of π as more random points accumulate.

Once a large sample size is reached, it holds briefly to show the final estimate, then a fresh run starts scattering points from zero.

Estimating pi with random darts

The Monte Carlo method uses randomness to compute things that would be tedious to work out directly. Stanisław Ulam conceived the modern version in the late 1940s while working on nuclear weapons projects at Los Alamos, after wondering whether playing many solitaire games and counting the wins beat calculating the odds. He discussed it with John von Neumann, and Nicholas Metropolis suggested the name, a nod to the Monte Carlo Casino in Monaco where Ulam’s uncle gambled.

The pi experiment works by geometry. A circle of radius one sits inside a square of side two. The circle covers pi over four of the square’s area, so if you throw points uniformly at random into the square, the fraction landing inside the circle should approach pi over four. Multiply that fraction by four and you have an estimate of pi.

The catch is how slowly the error shrinks. It falls in proportion to one over the square root of the number of points, so quadrupling the points only halves the error, and one extra correct decimal digit needs roughly a hundred times as many throws. That is why the estimate wanders early on. The same rate holds however many dimensions a problem has, which is why Monte Carlo is valued for its generality rather than its efficiency on a simple task like this.

A worked example

After just a few hundred real random points, the estimate is often noticeably off; by tens of thousands of points, it genuinely settles in close to 3.14159, exactly as the real law of large numbers predicts.

Settings & tips

Frequently asked questions

Is this really estimating π?
Yes — a real Monte Carlo method; the ratio of points inside the circle to the total genuinely converges toward π.
Why does the estimate wobble early on?
With few real random samples, chance causes real variance; the estimate only settles down as the sample size grows large.
Is a key needed?
No — it is a pure local computation.
Is it free?
Yes — free, no download, in your browser.
Why does each extra digit take so many more points?
The error shrinks as one over the square root of the sample size, so reducing it by a factor of ten needs about a hundred times as many random points.
Why multiply the ratio by four?
The circle covers pi over four of the square’s area, so the share of points landing inside approaches pi over four. Multiplying by four turns that into pi.
Where did the name Monte Carlo come from?
Nicholas Metropolis suggested it, after the Monte Carlo Casino in Monaco where Stanisław Ulam’s uncle gambled. It was a code name for secret work at Los Alamos.

← All Science & Research screensavers