Monte Carlo Pi Estimator
Estimate pi by scattering random points in a square and counting how many land inside the circle, and watch the error shrink with the square root of the sample size rather than with the sample size.
Last reviewed by the Radiatus Cloud team
Need this done properly for your business?
Radiatus delivers secure cloud, DevOps & compliance engineering.
The method is a ratio of areas
Scatter points uniformly in a square of side two, centred on the origin, and count the fraction landing within distance one of the centre. That fraction approaches the ratio of the circle's area to the square's, which is pi over four, so four times the fraction estimates pi. Nothing about the geometry is special: the same technique estimates any area whose boundary you can test membership against, which is why it generalises to integrals in hundreds of dimensions where no other method is practical.
Accuracy improves with the square root of the samples
The standard error falls as one over the square root of n, so a hundred times more points buys one more decimal digit. That is the central fact about Monte Carlo methods and it cuts both ways: the convergence is slow, and it is slow at exactly the same rate regardless of how many dimensions the problem has. For a one-dimensional integral that is terrible compared with the alternatives; for a fifty-dimensional one it is the only approach that works at all.
The error is random, so it does not decrease monotonically
A run with more samples can produce a worse estimate than one with fewer. That is not a bug and it is the thing people find hardest to accept about the method: the guarantee is about the distribution of errors, not about any particular run. Running the same estimate several times and seeing the spread is far more informative than a single run reported to six decimal places.
Related tools
- Data Collection Analysis — Analyze app description to infer data collection.
- Dark Pattern Detector — Scan UX text for manipulative patterns.
- AI Risk Disclosure — Generate disclosure text for AI features.
- Maturity Radar — Generate a radar chart of security maturity.
Frequently Asked Questions
Why does multiplying by four give pi?
Because a circle of radius one has area pi and the square that encloses it has area four, so the fraction of points inside the circle approaches pi over four.
How fast does it converge?
The error falls as one over the square root of the sample count, so a hundred times more points buys roughly one more correct decimal digit. That is slow, and it is the same rate in any number of dimensions.
Why would anyone use this for pi?
Nobody would. It is a demonstration. The method matters for integrals in high dimensions where every other technique fails, and pi is just the clearest illustration of it.
Why did more samples give a worse answer?
Because the error is random. The guarantee is about the distribution of errors across runs, not about any single run improving on the last.
Does the random number quality matter?
For this demonstration, hardly. For serious Monte Carlo work it matters a great deal, and low-discrepancy sequences beat ordinary random numbers by converging closer to one over n than one over the square root of n.
Privacy & Security
Everything runs in your browser; nothing is uploaded.
How to Use
Choose a sample size and run the estimate.
Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.