🎯 Monte Carlo Pi Estimation
About this simulation
The Monte Carlo method uses repeated random sampling to approximate quantities that are hard to compute directly. Here it estimates π by dropping random points into a unit square and checking what fraction land inside the quarter circle inscribed in that square. As the number of samples grows, the observed fraction converges to the true geometric probability, revealing π.
How it works
- Each point (x, y) is drawn uniformly from the unit square [0,1]×[0,1].
- A point is “inside” if x²+y² ≤ 1, meaning it falls within the quarter circle of radius 1.
- The area of the quarter circle is π/4, and the area of the square is 1, so the probability a random point lands inside is π/4.
- Multiplying the observed inside-fraction by 4 gives an estimate of π that improves, on average, as more points are sampled.
Key equations
P(inside) = area(quarter circle) / area(square) = (π/4) / 1
π ≈ 4 × (points inside / points total) — the estimate is unbiased but noisy, and its error shrinks proportionally to 1/√N by the central limit theorem.
Controls
- Points per frame — how many random points are added each animation frame.
- Convergence chart — show or hide the running-estimate-vs-π line chart.
- Pause / Reset — freeze the animation or clear all sampled points and start over.
Did you know?
Monte Carlo methods were formalised in the 1940s by Stanislaw Ulam and John von Neumann while working on nuclear weapon design at Los Alamos, and the technique is named after the Monte Carlo Casino because of its reliance on randomness. Today it underlies risk modelling in finance, rendering in computer graphics, and particle physics simulations.