🎯 Monte Carlo Pi Estimation
Estimate the value of π by scattering random points into a square and counting how many land inside a quarter circle. Watch the Monte Carlo estimate converge live, with a running error chart.
About this simulation
This tool demonstrates the Monte Carlo method by estimating π from pure randomness. Thousands of points are scattered uniformly across a unit square, and each is tested against the equation of a circle to see whether it falls inside the inscribed quarter circle. Because the ratio of the quarter circle's area to the square's area is exactly π/4, multiplying the observed inside-fraction by four produces a running estimate of π that gets steadily more accurate as more points are sampled.
🔬 What it shows
Random points (x, y) are drawn uniformly from [0,1]×[0,1]. A point counts as inside when x²+y² ≤ 1. Since area(quarter circle)/area(square) = π/4, the fraction of points inside approximates π/4, so π ≈ 4·(inside/total). The chart tracks this running estimate against the true value of π.
🎮 How to use
Adjust the points-per-frame slider to sample faster or slower, toggle the convergence chart on or off, and use Pause to freeze the animation or Reset to clear all points and start a fresh run. The stats box shows live counts, the current π estimate and its absolute error against Math.PI.
💡 Did you know?
This is the same style of statistical sampling used to price complex financial derivatives, simulate neutron transport in nuclear reactors, and render realistic lighting in movies — anywhere an exact answer is too hard to compute but a good random estimate is achievable.
Frequently asked questions
How does randomly scattering points estimate π?
A quarter circle of radius 1 inscribed in a unit square has area π/4, while the square has area 1. If points are scattered uniformly across the square, the probability any one lands inside the quarter circle equals that area ratio, π/4. Counting the fraction of points that land inside and multiplying by 4 therefore estimates π.
Why does the estimate keep changing as more points are added?
Each batch of random points is a fresh statistical sample, so the observed inside-fraction fluctuates around the true value of π/4. As the total number of points N grows, the law of large numbers pulls the running estimate closer to π, and the typical error shrinks proportionally to 1/√N.
Why is the Monte Carlo pi estimate not exact?
It is a statistical estimate rather than an exact calculation. Because each point's position is random, the count of points inside the quarter circle is itself a random variable, so the estimate always carries some sampling error. That error shrinks with more samples but never fully disappears in a finite run.
How fast does the Monte Carlo method converge?
Monte Carlo estimates typically converge at a rate of 1/√N, meaning you need roughly 100 times more samples to gain one extra decimal digit of accuracy. This is much slower than deterministic numerical methods for smooth one-dimensional problems, but Monte Carlo scales far better to high-dimensional problems where those methods become impractical.
What is the Monte Carlo method used for beyond estimating π?
Monte Carlo methods are used wherever a problem is too complex to solve exactly but can be approximated through repeated random sampling: pricing financial options, simulating particle physics and nuclear reactions, rendering global illumination in computer graphics, optimisation, and Bayesian statistical inference, among many other applications.
Estimate the value of pi by scattering random points into a square and counting how many land inside a quarter circle, watching the Monte Carlo estimate converge live.
2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install