Monte Carlo Simulation Explained: Randomness as a Tool

You can't always compute an answer with a formula. But you can almost always guess it, randomly, thousands of times, and let the guesses average out to something remarkably close to the truth. Here's how, and why it works.

By Petrus Sheya

August 3, 2026 · 6 min read

How do you find the area of a shape you don't have a formula for?

Here's a strange way to do it. Blindfold yourself. Stand in a square courtyard with a circular fountain in the middle. Throw a pebble over your shoulder. Do it again. And again, a thousand times.

You have no idea where any single pebble will land. But after a thousand throws, count how many landed inside the fountain versus how many landed in the courtyard. That ratio tells you something real: the fountain's area, as a fraction of the courtyard's area.

That's the entire idea behind Monte Carlo simulation. Take a question you can't answer directly. Turn it into random guesses. Average the guesses. Watch the average land suspiciously close to the truth.


You don't need a formula. You need enough darts.

Let's make the courtyard exact: a square from 1-1 to 11 on each side, so it has area 44. Inside it, a circle of radius 11, centered at the origin, with area πr2=π\pi r^2 = \pi.

Throw a dart at a random point in the square. It either lands inside the circle or it doesn't. Do this many times, and the fraction of darts landing inside the circle should equal the fraction of the square's area that the circle covers:

darts inside circletotal dartsarea of circlearea of square=π4\frac{\text{darts inside circle}}{\text{total darts}} \approx \frac{\text{area of circle}}{\text{area of square}} = \frac{\pi}{4}

Flip that around and you've got a way to estimate pi from nothing but random points and a bit of counting:

π^4darts insidetotal darts\hat\pi \approx 4 \cdot \frac{\text{darts inside}}{\text{total darts}}

Every dart lands somewhere in the square. Watch the ratio of hits inside the circle settle toward pi over 4.

Inside / total29 / 40
Estimate of pi2.9000
Error0.2416

Watch the dots pile up. Green means inside the circle, red means outside. Drag the slider back and forth, or hit play and let the darts fly. With a handful of darts the estimate jumps around wildly. With a few hundred, it settles in around 3.14. No calculus, no formula for pi. Just random points and a ratio.


One run isn't the answer. It's a guess.

Here's the part that trips people up. If you throw 60 darts and get an estimate of 3.2, that doesn't mean Monte Carlo is broken. It means you got one noisy sample of a random process. Throw another 60 darts and you might get 3.0. Another 60, and maybe 3.3.

Each full run of the experiment is itself a single roll of the dice. The estimate you get depends on exactly which random points happened to land where. A single run tells you an answer. It doesn't tell you how much to trust it.

This runs the whole dart-throwing experiment 240 times at the same N. Drag N and watch the spread of answers shrink.

true piestimate of pi (one dot of the histogram = one full run of N darts)
Runs240
Std. deviation0.2151
Range2.533.80

This runs the whole dart-throwing experiment 240 separate times, all at the same NN, and plots every result as a bar in a histogram. Set NN low and the bars spread wide, some runs guessing 2.8, others guessing 3.5. Drag NN up and the spread collapses toward a tight cluster around pi. More darts per run doesn't just improve one estimate. It shrinks the entire range of answers you could have gotten.


More darts help less than you'd think.

So precision improves with more samples. But by how much? Here's the part that catches people off guard: doubling your darts does not halve your error. You need four times as many darts to cut the error in half, because the error shrinks with the square root of NN, not NN itself.

We write the expected spread of the estimate this way, where σ\sigma measures the underlying randomness of a single dart landing inside or outside:

expected errorσN\text{expected error} \approx \frac{\sigma}{\sqrt{N}}

This is the law of large numbers doing its work, and the square root is not a technicality. It's the whole story of why simulation has diminishing returns.

The shaded band is the expected spread, one standard deviation, at each N. It shrinks with the square root of N, not N itself.

true pinumber of darts thrown (square-root scale)
N1
Estimate4.0000
Error0.8584
Expected spread± 1.6422

Hit play and watch a single long run unfold. The shaded band shows the expected spread at each point, and notice how fast it narrows early on, then how stubbornly slow it narrows later. Going from 10 darts to 40 darts shrinks the band by half. Going from 1,000 to 4,000 shrinks it by the same half. Same factor of improvement, four times the work, every single time.


The darts don't care what shape you're throwing them at.

Here's where it gets genuinely useful. Nothing about this trick actually requires a circle. The dart-and-ratio method was just a special case of a much bigger idea: you can estimate the average value of anything by sampling it randomly and averaging the samples.

Take some curve, any curve, over an interval. Instead of asking "does the dart land inside the shape," ask "how high is the curve at this random point." Average enough of those heights, and you've estimated the area under the curve, otherwise known as its integral.

abf(x)dx(ba)1Ni=1Nf(xi)\int_a^b f(x)\,dx \approx (b - a) \cdot \frac{1}{N}\sum_{i=1}^{N} f(x_i)

No circles this time, just a curve. Sample random points along it and average the heights: that average estimates the area underneath.

true integralx sampled uniformly on [0, 1]
Estimate0.7080
True integral0.6366
Error0.0713

Drag the sample count up and watch the dashed green line, the running average of sample heights, drift toward the dashed gold line, the true area under the curve. Hover over any red dot to see exactly what value it contributed. No formula for the area under a sine curve was needed here either. Random sampling plus averaging works on any function you can evaluate, not just circles.


Why simulate what you could calculate?

For a circle or a sine wave, you don't actually need Monte Carlo. Both have exact formulas. So why bother?

Because most real problems don't. Pricing a financial option whose payoff depends on a stock path with dozens of possible twists. Simulating how light bounces around a rendered 3D scene. Estimating a 50-dimensional integral in a physics model, where laying down a grid of sample points would need more points than atoms in the universe just to cover the space. In all of these, nobody has a clean formula, and grid-based methods choke as the number of dimensions grows.

Random sampling doesn't care how many dimensions the problem has. It just needs to draw a valid sample and evaluate it. That's why Monte Carlo methods run inside video game engines, financial models, and physics simulators alike. It's the same dart-throwing idea from the courtyard, just aimed at problems too tangled for exact math.


The short version

Monte Carlo simulation answers hard questions with random sampling instead of exact formulas. Throw enough random points at a problem, average what you find, and the average converges to the true answer. A single run is noisy. Many runs at the same sample size reveal a spread that narrows as you add more samples, shrinking specifically with the square root of NN. And the trick generalizes far past circles and darts: any average of random samples estimates the true average, which means Monte Carlo can tackle integrals, probabilities, and predictions that have no closed-form answer at all.

The next time you can't compute something exactly, remember: you don't need the formula. You just need enough darts.