This simulation needs WebAssembly, and it could not start in this browser.
The image is a frame from a real run. Check that JavaScript is on, or try another browser.
Throw points at random into a square with a circle drawn inside it. The fraction that lands in the circle is the ratio of the two areas, , so counting hits gives an estimate of . The same trick computes integrals that no grid can handle: in many dimensions a grid needs astronomically many points, while the error of random sampling falls as no matter how many dimensions there are. Ulam and von Neumann developed the method at Los Alamos in the 1940s, and it now runs in particle physics, finance and rendering.
What you see
Points inside the circle are green, points outside gray, the most recent 40 000 of them with older ones fading. The top left shows the running estimate, the number of points and the error against the true value of .
Equations
With points of which land in the circle,
since each point is a coin flip that comes up inside with probability . A hundred times more points buy one more correct digit. Over 40 runs of 100 000 random points each, the errors scatter exactly as this predicts.
Quasi-random points do better. The Halton sequence writes the index in base 2 and base 3 and mirrors the digits behind the decimal point, which gives the two coordinates. Its points avoid each other and fill the square evenly, so the error falls faster than : from to points it drops twenty times, where random sampling gains a factor of ten. After 100 000 Halton points the estimate is more than ten times closer than the typical random one.
Presets
Random points: 500 pseudo-random points per frame. The estimate wanders and settles slowly.
Halton sequence: 500 Halton points per frame. The estimate locks in within a few seconds, and the points form an even, regular-looking pattern.
Many random points: 5000 per frame, to watch the convergence over a few million points.
Many Halton points: 5000 per frame; after a million points the estimate is off by about .
Parameters
Halton sequence: quasi-random instead of pseudo-random points. Switching starts a new count.
Points per frame: 10 to 5000. Applies live.
Show the points: hide them to see the estimate alone.