Monte Carlo π
Random points land inside a square. The ratio that fall inside the inscribed circle estimates π/4. More samples mean a better estimate.
Cyan points are inside the circle; grey points are outside. The ratio inside ÷ total approaches π/4. Refresh the page or press Reset to start a fresh simulation.
What you are seeing
The square has side 2 and the circle has radius 1. The circle area is π; the square area is 4.
The probability that a uniform random point lands inside the circle is π/4.
Multiply the inside ratio by 4 to estimate π. The error shrinks roughly like 1/√n.
Why it matters
Monte Carlo methods are used in physics, finance, graphics, and machine learning. This is the simplest possible introduction to sampling-based estimation.
Complexity & details
Time: O(n) for n samples. Error decreases as O(1/√n), independent of dimension.
Frequently asked questions
Why is the estimate noisy?+
Each sample is random, so the running ratio fluctuates. Averaging more samples reduces the standard error by about 1/√n.
Why use Monte Carlo if it is slow?+
It scales well to high-dimensional problems where exact integration is impossible. The convergence rate does not depend on dimension.