How can random points tell us something about a constant as precise as \(\pi\)? The answer begins with a shape whose area we know, and a count whose fraction we can estimate. This experiment needs only the idea of an area ratio; the random sampling makes that ratio visible.
Turn area into a probability
Draw a square with sides of length one. Put a quarter of the unit circle inside it, centred at the lower-left corner. The square has area \(1\), and the quarter-circle has area \(\pi/4\).
Choose a point uniformly inside the square. “Uniformly” means equal areas have equal chances of containing the point. The probability of landing inside the circle is therefore the same as its fraction of the square:
Count the points that satisfy this test. If \(k\) of \(n\) points land inside, the observed fraction is \(k/n\), giving the estimate
For example, 787 points inside out of 1,000 gives \(3.148\). That is an arithmetic illustration, rather than a recorded run of the demonstration. Your chosen seed and sample count determine the result displayed in the experiment.
Try the experiment
Start with the default settings. The point cloud shows the geometry; the convergence chart shows how the estimate changes as points accumulate. Increase the sample count, then try a different seed.
The seed initializes a deterministic pseudorandom generator. Repeating the same seed and sample count reproduces the same generated points. This makes the demonstration inspectable: a surprising result can be repeated instead of disappearing on the next run.
The scatter view displays at most the first 2,000 points so that it stays readable. The estimate uses every point you request, up to the tool's 50,000-point limit. The CSV export contains the full generated sample, including each point's coordinates, classification, and running estimate.
| Change | What to look for |
|---|---|
| Increase the sample count | A less variable estimate over many possible runs |
| Keep the seed fixed | The same initial points and a longer continuation |
| Change the seed | A different sequence and a different path toward \(\pi\) |
| Export the CSV | A way to check the count independently |
Why the estimate wanders
Each generated point produces a yes/no outcome: inside or outside. In an ideal model with independent uniform samples, this is a Bernoulli trial with success probability \(p=\pi/4\). The standard deviation of the resulting estimate is
The denominator contains \(\sqrt{n}\), so reducing the typical sampling variation by half takes approximately four times as many points. Adding ten times as many points does not normally buy ten times the precision.
A single path need not improve at every step. A new inside point raises the estimate; a new outside point lowers it. Either move can take it farther from \(\pi\). The statistical promise concerns variation across repeated samples, not monotonic progress within one run. General Monte Carlo methods use this same idea of estimating a quantity by averaging sampled outcomes. StatLect's explanation develops that connection.
Check the calculation
The core computation is small enough to inspect directly:
import random
rng = random.Random(42)
n = 10_000
inside = 0
for _ in range(n):
x, y = rng.random(), rng.random()
inside += x * x + y * y <= 1
estimate = 4 * inside / n
This Python example implements the same method, but uses Python's generator. Its seed value will not reproduce the browser's coordinates because the generators differ.
This is an educational estimate, not an efficient way to compute many digits of \(\pi\). The points are generated data, not physical observations. Pseudorandom output also approximates the independent sampling model rather than proving it. What the experiment teaches is more useful than the final decimal: a clear model, a repeatable sample, and an honest account of variation.