What Monte Carlo methods are
Monte Carlo methods apply randomness together with the Law of large numbers to scientific and engineering problems. One of the earliest documented uses was by Stanislaw Ulam and John von Neumann for nuclear weapon simulations after WWII.
The classical case: numerical integration
Estimating pi by throwing darts is the standard introduction. Take a square board with an inscribed quarter circle, throw darts uniformly across the square, and note whether each lands inside the quarter circle. The ratio of hits inside the circle to total throws approaches the ratio of the quarter circle's area to the square's.
With a square side length of 1, the simulation produces an estimate of pi directly. The method works, but not well: even with 1000 samples, repeated runs scatter widely around the true value. Roughly 10 billion samples are needed to estimate pi to four digits after the decimal with reasonable reliability. For independent trials like these, the typical sampling error shrinks in proportion to the square root of N, so halving the error requires four times the samples.
The exercise is more than whimsical. The simulation estimates the area under the quarter-circle curve, which is a definite integral. Many integrals resist analytical solution, and Monte Carlo methods are especially valuable for high-dimensional integrals, where other numerical methods become prohibitively expensive.
Combinatorial problems: counting SET hands
Monte Carlo simulation is also useful for combinatorial questions that have no analytical solution and whose full enumeration is intractable. The game of SET is a good example. Each card carries four attributes:
- Number of shapes (1, 2 or 3)
- Color (Red, Green or Purple)
- Shape type (Oval, Diamond or Squiggle)
- Shading (Empty, Striped or Solid)
A "set" is three cards that are, for each attribute separately, either all different or all the same. From a deck of 81 cards, the number of ways to deal a 12-card hand is straightforward to compute, but no simple counting formula says how many of those hands contain no set. Enumerating roughly 70 trillion hands is impractical. Donald Knuth attacked the problem with a clever program (setset-all, available on his programs page) that takes advantage of symmetries and other mathematical properties of SET to shrink the search space; it found 2,284,535,476,080 such hands, giving a 3.23% chance that a randomly drawn 12-card hand contains no set.
A Monte Carlo simulation reaches the same answer without any of that mathematical machinery, by repeatedly drawing a hand and checking it for sets. After 10 million simulated draws, the result was 0.0323, matching the exact figure closely.
The approach scales gracefully. Asking the same question for a 15-card hand multiplies the search space by roughly 100, which would be a serious burden for exact enumeration. For the simulation it is a one-parameter change, and it returns a reliable answer of about 0.00037.
Financial planning: retirement projections
Retirement projections are a domain where Monte Carlo methods are ubiquitous. Consider a retiree with a $1,000,000 portfolio who wants to withdraw $30,000 a year for living expenses. A naive estimate focuses on two factors: portfolio return and inflation. Assume an average yearly portfolio return of 4% and average yearly inflation of 2%.
Denoting return as r and inflation as i, the real return in a year is (1+r)/(1+i). Starting from $1,000,000, the portfolio holds $1,019,600 at year's end; after a $30,000 withdrawal, $989,600 remains. Carried forward, the money runs out after about 55 years — apparently safe for someone retiring at 65.
That reasoning is too simplistic. Averages poorly represent reality when the underlying factors carry uncertainty. Sequence of returns matters: a -10% year followed by a +18% year averages to 4%, but leaves significantly less money than two consecutive +4% years. Inflation is likewise unpredictable and sometimes correlated with portfolio returns; high inflation combined with low or volatile returns can do serious damage.
Once variance in yearly withdrawals, mixed asset portfolios, life expectancy, unexpected events and changing tax laws enter the picture, single-average estimates become misleading. Monte Carlo simulation handles this naturally: by drawing from distributions grounded in historical data, it can run a million scenarios and report things like the odds that funds run out before death.
In one such simulation, the top chart shows a dashed line for the constant assumptions (4% return and 2% inflation every year) alongside shaded blue regions covering 1,000,000 simulations that drew inflation and return from normal distributions based on historical data. In about 25% of the cases, the money was fully depleted by roughly 22 years.
The bottom chart makes the duration question easier to read: the odds that the plan funds 30 years come out to about 60%, since 40% of the simulations were depleted by that point.
Under these assumptions, the plan looks considerably riskier than the average-value estimate suggests. For a 65-year-old planning on 25 years of retirement, roughly 30% odds of insufficient funds are sobering, and a change of plans — a more frugal lifestyle, say, or additional funds from another source — may be warranted.
Retirement is only one of many financial and economic applications. The uncertainty in these domains makes analytical planning difficult, and company sales projections, growth projections and stock offering prices all lean on Monte Carlo estimates with meaningful error bars.
Source code
All code for these explorations is available on GitHub.



