Monte Carlo Pi Explorer

random points and convergence behavior

Loading interactive simulation...

why error shrinks slowly 🖖

Monte Carlo error shrinks proportional to 1/โˆšN, not 1/N โ€” a consequence of the Central Limit Theorem, since the estimate is an average of N independent inside/outside coin flips whose variance falls as 1/N. That square root is expensive: gaining one more correct decimal digit takes roughly 100ร— more points, not 10ร—, which is why the point cloud can look convincingly circular long before the digits stop wobbling. It's also why this method rarely gets used just to compute ฯ€ in practice โ€” it earns its keep on high-dimensional integrals, where deterministic grid methods scale exponentially with dimension but Monte Carlo's 1/โˆšN rate doesn't care how many dimensions you're in.

a fixed answer from pure luck 🖖

Here is the strange part: ฯ€ is a fixed, exact number, yet this tool pins it down using nothing but chance. Each single point lands unpredictably, inside or outside the circle by luck alone. But their running average behaves โ€” the Law of Large Numbers guarantees that as you pile on points, the noisy fraction settles toward one stable value. The takeaway: randomness, averaged in bulk, becomes a dependable measuring instrument.

the needle that cheated 🖖

Long before points on a screen, Buffon's needle (1777) estimated ฯ€ by dropping needles across evenly spaced lines โ€” arguably the first Monte Carlo experiment. In 1901 Mario Lazzarini reported that 3,408 tosses gave ฯ€ = 3.1415929, right to six decimals. The catch: that is exactly 355/113, a famous old approximation, and 3,408 is suspiciously the precise number of throws needed to hit it โ€” he almost certainly stopped the instant luck matched the target.

Problem solved in full

  1. Judging whether 3.122 is a bad run from 2000 points 5 steps

    Is 3.122 a bad run? The default state draws N = 2000 points from seed 42, and 1561 of them land inside the quarter circle. Work out what an ordinary count would have been before judging the estimate.

    1. Each point is one trial that succeeds if it falls in the quarter disc, and because the enclosing square has area 1, the success probability is that area outright. Over 2000 independent trials the count is binomial, and a binomial's mean is the trial count times the probability.

    2. The same two numbers fix the spread. The observed count is under ten short of expectation, which is barely half a standard deviation, so this seed is an ordinary one โ€” worth establishing before anything gets blamed on it.

    3. The estimate is the count multiplied by a fixed constant, so its standard deviation is the count's multiplied by that same constant. This is where the familiar 1/โˆšN enters: the count's spread grows like โˆšN while the division is by N.

    4. The printed error has to come out at the same 0.53 standard deviations, because multiplying by a constant cannot move a value relative to its own spread. It is one fact in two units, not two facts.

    5. Now the part no seed can fix. Four times an integer over 2000 is always a multiple of 0.002, and ฯ€ is irrational, so it is never one of them โ€” the error cannot reach zero, and the closest the estimator can physically land is one step off the grid.

    Answer

    The tool prints 1561 points inside, an estimate of 3.122000, and an error of 1.959 ร— 10โปยฒ against 3.141593. A typical error at N = 2000 is 0.0367, so this run is better than average rather than worse, and roughly three seeds in five would do worse than 42 did. The floor from step 5 is 4.073 ร— 10โปโด: no seed at this N can beat it, because nothing the formula can output lies closer to ฯ€ than that. It is 90 times smaller than the typical error, so the grid is nowhere near the limiting factor, and the gap widens with N rather than closing โ€” the floor falls like 1/N while the random error falls only like 1/โˆšN. That also settles a claim you will meet about this method: six correct decimals from a couple of thousand trials is not a lucky run but an arithmetically unreachable one, since at N = 2000 nothing the estimator can produce is even correct to the fourth decimal place.

References (1)

Example problems

  • small N - Small sample count gives high variance estimate.
  • medium N - 1,561 of the 2,000 points land inside the quarter circle, so the estimate is 3.122000 and the error is 1.959ร—10โปยฒ. The seed is fixed, so it is the same 1,561 every time you press this. What moves in the error chart is the estimate settling as points accumulate, not the tool rerolling the dice.
  • large N - Larger sample count tightens estimate around pi.