Monte Carlo simulation estimates a quantity by repeated random sampling. Instead of solving for the output distribution of a complicated system analytically, you draw the inputs at random from their assumed distributions, compute the output for each draw, and summarise the results. It is the standard way to propagate tolerances, variability and uncertainty through a calculation that has no tidy closed form.
The loop:
The estimator. To estimate an expectation $E[g(X)]$, such as a failure probability, draw $X_1,\dots,X_N$ independently and average. The error of the average falls with the square root of the number of runs, regardless of how many inputs the system has:
The last form is the usual interval when the output is a pass or fail indicator and $\hat{p}$ is the observed proportion of failures.
Worked example. Four layers are stacked, each with a thickness uniformly distributed between $9.5$ and $10.5$ mm, and the stack must not exceed $41$ mm. A worst-case view adds the maxima to $42$ mm, which always fails the spec and says nothing about how often. A root-sum-square view gives a spread of $\sqrt{4/12}=0.577$ mm around a $40$ mm mean. Simulation answers the actual question: how often does the total exceed $41$ mm? For this textbook case the exact answer is known, $1/4!=1/24=4.17\%$, which lets us watch the simulation converge. With a fixed seed of $42$:
With $N=100$ runs the estimate is $4.00\%$, but its $95\%$ band, $0.2\%$ to $7.8\%$, is as wide as the answer itself. At $10{,}000$ runs the estimate is $4.25\%$ with a standard error of $0.20$ points, and at $1{,}000{,}000$ it is $4.16\%$ with $0.02$ points. Repeating the $10{,}000$-run experiment $300$ times gives estimates that scatter with a standard deviation of $0.197$ points against a theoretical $0.200$. The simulated stack also has a mean of $40.00$ and standard deviation of $0.578$, matching the $0.577$ calculated above.
How many runs do you need? Solving the interval half-width $E$ for $N$ gives the planning formula:
To pin the failure rate down to $\pm0.1$ percentage points at $95\%$ confidence, $E=0.001$, so $N\approx1.96^2(0.0417)(0.9583)/0.001^2\approx153{,}000$ runs. Halving the error needs four times as many runs, which is the price of a method that works for any system.
Where plain simulation struggles.
- Rare events: the chance that the stack exceeds $41.8$ mm is $0.2^4/4!\approx0.0067\%$. In $100{,}000$ runs you expect only about $7$ hits, so the estimate carries roughly $39\%$ relative error. For events this rare, use importance sampling or splitting rather than brute force.
- Wrong inputs, wrong answer: the simulation faithfully reproduces whatever distributions you feed it. Correlated inputs, truncated tails or an invented distribution give a precise but wrong result. Check the inputs against measured data.
- Seeds and reproducibility: record the random seed and software version, or the result cannot be reproduced exactly.
- Variance reduction: antithetic variates, control variates and stratified or quasi-random sampling (such as Sobol sequences) can cut the number of runs needed by large factors.
- Report the uncertainty: quote the estimate with its standard error or interval. A single Monte Carlo number with no error bar looks more exact than it is.
- Versus the bootstrap: both resample, but Monte Carlo draws from a model you specify, while the bootstrap draws from the data you collected.
Read Monte Carlo simulation as running the experiment on a computer instead of in the fab: describe the randomness, play it out many times, and count; the answer sharpens with the square root of the effort.