Mathematics · Simulator 050
Scatter random points over a square and count how many land inside a shape. That fraction estimates the shape's area. Use it to estimate π, or the area under a curve, and see how slowly but surely the estimate improves as the points pile up.
If points are uniform over a square of area A, the fraction landing in a region estimates that region's area divided by A. For a quarter circle of radius 1 inside the unit square, the area is π/4, so
π ≈ 4 × (points inside) / (total points)
Each point is a yes/no trial with probability p, so the estimate's standard error is √(p(1 − p)/n). It shrinks like 1/√n: 100 times more points give only 10 times more accuracy. The log–log error chart shows this slope of −½.
Monte Carlo methods are slow for simple 2-D areas, but they handle high-dimensional problems where grid methods are hopeless, from particle physics to finance. A seeded generator makes runs reproducible; change the seed to see run-to-run scatter.
Pseudo-random numbers (Mulberry32) are not truly random but are fine for this purpose.
How many random points would you need to estimate π to about ±0.001 (one standard error)?
Standard error ≈ 4√(p(1 − p)/n) with p = π/4, so 4√(0.1686/n) = 0.001, which gives n ≈ 2.7 million. Each extra correct digit costs 100 times more points.