๐ฅง Monte Carlo Pi Estimator
Scatter a large number of random points inside a 1ร1 square and estimate pi from the fraction that land inside a quarter circle of radius 1 โ the classic "Monte Carlo method" simulation. A hands-on way to see randomized numerical estimation in action.
How to use
- Set the number of points to scatter (sample size).
- Press "Run simulation" to scatter random points across the square.
- Pi is estimated from the ratio of points inside the quarter circle (green) to the total (green + red).
FAQ
Why does this method estimate pi?
A quarter circle of radius 1 has area ฯ/4, while the 1ร1 square containing it has area 1. Scattering points uniformly at random, the fraction landing inside the quarter circle approaches ฯ/4, so multiplying that fraction by 4 gives an estimate of pi.
What happens if I increase the number of points?
In general, a larger sample size tends to bring the estimate closer to the true value of pi (3.14159...), though since it's a random estimate, individual runs will still vary somewhat.
Are all the points actually drawn on screen?
To keep rendering fast, only up to 4,000 points are drawn visually. The pi estimate itself, however, is calculated using the full sample size you specify.