Written and maintained by CASRAI Editorial Board
Last updated
Monte Carlo simulation estimates a quantity by drawing many random inputs from stated probability distributions, running each draw through a model, and summarising the results. The answer is a distribution of outcomes, not a single number, and its precision is something you can calculate. This guide gives the definition, the formula, a worked example with every step of the arithmetic, the number-of-trials guidance in the metrology standard JCGM 101:2008, and a reporting template.
What is Monte Carlo simulation? (definition)
Monte Carlo simulation is a numerical method that approximates a quantity of interest, such as a probability, an average or an uncertainty interval, by repeated random sampling. You (1) write a model that turns inputs into an output, (2) assign each uncertain input a probability distribution, (3) draw one value from each distribution, compute the output, and repeat the draw many times, and (4) summarise the collected outputs with a mean, a standard error and a percentile interval.
It is useful when the model is too complicated to solve with algebra. The metrology standard JCGM 101:2008 (Supplement 1 to the GUM, published by the BIPM) describes it as a general numerical approach for models with a single output quantity whose inputs are characterised by any specified probability density functions, and as a practical alternative to the GUM uncertainty framework when the model’s complexity makes that framework hard to apply.
Do not confuse it with Markov chain Monte Carlo. Plain Monte Carlo draws independent samples from distributions you specify; MCMC builds dependent samples to explore a distribution you cannot sample directly. The separate guide on Markov chain Monte Carlo covers that method.
Monte Carlo simulation formula
There is one core formula: the sample average of the model output over n random draws estimates the expected value.
θ̂ = (1/n) Σ g(xi), for i = 1 to n
- g is the model or function that turns one set of inputs into an output.
- xi is the i-th random draw of all the inputs, each taken from its own assigned distribution.
- n is the number of trials (draws).
- θ̂ is the Monte Carlo estimate of the true expected output.
The precision of the estimate is its standard error:
SE = s / √n
where s is the sample standard deviation of the n outputs. When the quantity is a probability, g is 1 if the event happens and 0 if not, the estimate p̂ is the proportion of trials with the event, and the formula becomes SE = √( p̂(1 − p̂) / n ). Because n sits under a square root, ten times more precision needs one hundred times more trials.
Worked example with real numbers: probability that two dice total 10 or more
This question has an exact answer, which lets you check the simulation. Of the 36 equally likely outcomes of two fair dice, the totals of 10 (4+6, 5+5, 6+4), 11 (5+6, 6+5) and 12 (6+6) give 3 + 2 + 1 = 6 favourable outcomes. The exact probability is 6/36 = 0.1667.
Now simulate it. Roll two virtual dice n = 10,000 times with the random seed set to 42 (Python’s built-in generator, code below). The event “total is at least 10” occurred in 1,709 trials.
- Estimate: p̂ = 1,709 / 10,000 = 0.1709
- Standard error: √(0.1709 × 0.8291 / 10,000) = √(0.141696 / 10,000) = √0.0000141696 = 0.00376
- 95% interval (normal approximation): 0.1709 ± 1.96 × 0.00376 = 0.1709 ± 0.0074, so 0.1635 to 0.1783
- Check: the exact value 0.1667 lies inside the interval, as expected.
The simulated estimate differs from the truth by 0.0042, about one standard error. That is sampling noise, and it is exactly what the standard error predicts. A different seed gives a slightly different estimate.
How many trials do you need?
Solve the standard error formula for n. To bring the standard error of this dice probability down to 0.005, you need n = p(1 − p) / SE2 = (0.1667 × 0.8333) / 0.0052 = 0.13889 / 0.000025 = about 5,556 trials. For uncertainty propagation, JCGM 101:2008 gives two pieces of guidance: choose the number of trials M large compared with 1/(1 − p) for a 100p% coverage interval, for example at least 104 times 1/(1 − p); and a value of M = 106 can often be expected to deliver a 95% coverage interval whose length is correct to one or two significant decimal digits. For p = 0.95, 1/(1 − p) = 20, so the first rule asks for at least 2 × 105 trials. The standard also describes an adaptive procedure that keeps adding trials until the results stabilise.
Monte Carlo simulation examples
Estimating pi
Draw n random points (x, y) uniformly in the unit square. A point falls inside the quarter circle when x2 + y2 ≤ 1. The quarter circle covers π/4 of the square, so π is estimated as 4 × (fraction of points inside). With n = 10,000 the standard error of that estimate is 4 × √(0.7854 × 0.2146 / 10,000) = 4 × 0.00411 = 0.0164, so expect the third digit to wobble from run to run.
Propagating measurement uncertainty
This is the use JCGM 101:2008 standardises. Each input quantity gets a probability distribution, each trial computes the output, and the sorted outputs give an estimate, a standard uncertainty and a coverage interval. The standard’s own illustration uses Gaussian inputs with M = 106 trials and reports an output with mean 0.00, standard deviation 2.00 and a 95% interval of −3.92 to 3.92. The NIST Uncertainty Machine (uncertainty.nist.gov) is a free tool built for this task; it asks for the number of realisations of the output quantity and a random number generator seed.
Other research uses
Sensitivity analyses that vary many uncertain inputs at once, such as the inputs behind a tornado diagram, the decision value calculations in expected value of perfect information, and simulation-based corrections in quantitative bias analysis all rely on the same sample-and-summarise loop.
Interpretation: reading the output
| Output | What it tells you |
|---|---|
| Mean of the outputs | The Monte Carlo estimate of the expected output (θ̂). |
| Standard error (s / √n) | How far the estimate itself may be from the true expectation. It shrinks as n grows. |
| Standard deviation of the outputs | The spread of the output caused by the input uncertainty. It does not shrink as n grows; it only becomes better estimated. |
| Percentile interval of the sorted outputs (for example the 2.5th to 97.5th percentile) | A 95% symmetric coverage interval for the output, the form JCGM 101:2008 describes for the output distribution. |
The most common confusion is between the standard error and the standard deviation. More trials make the standard error smaller; they never make the real-world uncertainty in the inputs smaller.
Assumptions and common mistakes
- The result is only as good as the model and the input distributions. Random sampling removes algebra problems, not modelling errors. If an input distribution is wrong, ten million trials will give a precise wrong answer.
- Independence is assumed unless you model otherwise. If two inputs move together, sampling them separately misstates the output spread. Model the correlation explicitly.
- Too few trials. A few hundred trials produce an interval whose own endpoints are noisy. Use the standard error formula and the JCGM 101 guidance above to choose n.
- No seed recorded. Without the seed and software version, nobody can reproduce your run. See reproducibility.
- Treating the percentile interval as a confidence interval. A percentile interval of simulated outputs describes the modelled output distribution; a confidence interval describes sampling variability in observed data. Label which one you report.
- Checking normality for the wrong thing. The normal approximation used for the dice interval applies to the average of draws, which is why it works for large n. The outputs themselves need not be normal; see normality of distribution when a method does assume it.
How to report a Monte Carlo simulation (APA example)
Report enough that a reader can rerun it: the model, each input distribution, the number of trials, the seed, the software and its version, and both the estimate and its precision. An illustrative template (the numbers are from the worked example above):
We estimated the probability that two fair six-sided dice total at least 10 by Monte Carlo simulation with 10,000 trials (Python 3 random module, seed = 42). The estimated probability was .17 (SE = .004, 95% CI [.16, .18]); the exact value is .17.
For uncertainty propagation, add the standard being followed (for example JCGM 101:2008), the distribution assigned to each input, and the coverage probability of the reported interval. APA style reports no leading zero for proportions that cannot exceed 1, as shown.
How to calculate it in Excel, R or Python
Excel
In A1:A10000 enter =IF(RANDBETWEEN(1,6)+RANDBETWEEN(1,6)>=10,1,0). Then =AVERAGE(A1:A10000) gives the estimate and =SQRT(AVERAGE(A1:A10000)*(1-AVERAGE(A1:A10000))/10000) gives the standard error. Excel recalculates these random draws on every edit and has no seed, so paste values before reporting.
R
set.seed(42)
n <- 10000
total <- sample(1:6, n, replace = TRUE) + sample(1:6, n, replace = TRUE)
p <- mean(total >= 10)
se <- sqrt(p * (1 - p) / n)
c(p, se, p - 1.96 * se, p + 1.96 * se)
R’s generator differs from Python’s, so its numbers will differ slightly from the worked example while estimating the same 0.1667.
Python
import random, math
random.seed(42)
n = 10000
hits = sum(1 for _ in range(n)
if random.randint(1, 6) + random.randint(1, 6) >= 10)
p = hits / n
se = math.sqrt(p * (1 - p) / n)
print(hits, p, se, p - 1.96 * se, p + 1.96 * se)
This prints 1709 hits and the estimate and interval shown in the worked example. For big simulations, trials are independent of each other, which makes them a natural fit for embarrassingly parallel jobs.
FAQ
What is Monte Carlo simulation in simple terms?
It is a way to find an answer by running a random experiment many times on a computer and averaging the results. If a problem has a known exact answer, as the two-dice example does, you can check that the simulation converges to it. If it does not, the standard error tells you how reliable the estimate is.
What is the difference between Monte Carlo simulation and MCMC?
Monte Carlo simulation samples independently from distributions you specify. MCMC creates a chain of dependent samples to explore a distribution that cannot be sampled directly. See Markov chain Monte Carlo.
How many simulations should I run?
Work backwards from the precision you need using SE = s / √n, and for uncertainty intervals follow JCGM 101:2008: at least 104 times 1/(1 − p) trials for a 100p% interval, with 106 often sufficient for a 95% interval accurate to one or two significant digits.
Why set a random seed?
A seed makes the pseudorandom sequence repeatable, so a reader running your code gets the same numbers. Report it alongside the software and version.
Sources
- Joint Committee for Guides in Metrology (JCGM), JCGM 101:2008, Evaluation of measurement data: Supplement 1 to the “Guide to the expression of uncertainty in measurement”: Propagation of distributions using a Monte Carlo method. BIPM. https://www.bipm.org/documents/20126/2071204/JCGM_101_2008_E.pdf (accessed 2026-10-29).
- National Institute of Standards and Technology, NIST Uncertainty Machine. https://uncertainty.nist.gov/ (accessed 2026-10-29).
- Metropolis, N., & Ulam, S. (1949). The Monte Carlo method. Journal of the American Statistical Association, 44(247), 335–341.








