Skip to content
FoundationSource checked

Monte Carlo Simulation

Estimates outcomes by running many random trials.

Quick Facts

Compact metadata for implementation and discovery.

Category
Simulation
Difficulty
Beginner
Family
Stochastic Simulation
Tier
Foundation
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
7
Code example
Not ready
Visualization
Ready
Aliases
Monte Carlo Method

Overview

Monte Carlo Simulation samples random inputs or events and summarizes the resulting distribution of outcomes.

Core Concepts

random trialsample averageuncertainty estimaterepeatable seedsimulated staterandom samplingsample selectionrandom draw

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(t)

Average

O(t)

Worst

O(t)

Space

O(1)

When to Use

  • Use it when a quantity can be estimated by repeated random trials.
  • Use it when exact analysis is difficult but sampling the process is straightforward.
  • Use it with confidence intervals or error estimates when reporting results.

When Not to Use

  • Avoid it when deterministic exact computation is cheap.
  • Avoid it when sampling from the required distribution is not possible or is biased.
  • Avoid reporting estimates without uncertainty or sample-count context.

What It Does

  • Runs repeated random experiments
  • Estimates averages, probabilities, or risk

Use Cases

  • Risk analysis
  • Physics and finance models
  • Estimating hard integrals

Inputs

  • Random input model
  • Trial count
  • Outcome function

Outputs

  • Estimated statistic
  • Outcome distribution

Key Formulas (1)

Monte Carlo estimate

estimate = ∑(sampleresults) / samplecount
estimate = sum(sample_results) / sample_count

Approximates a quantity by averaging many random trials.

Pseudocode

  1. 1.Define a random experiment
  2. 2.Run the experiment many times
  3. 3.Record the result of each trial
  4. 4.Aggregate the results
  5. 5.Return the estimated statistic

Canonical Example

Input
10000 random points in the unit square
Output
estimate of pi from the fraction inside the quarter circle
Explanation
The area fraction inside x^2 + y^2 <= 1 estimates pi / 4.

Implementation Notes

  • Define the random experiment and statistic before running trials.
  • Use a seedable random source for tests and experiments.
  • Track the number of samples, mean, and uncertainty estimate together.

Common Pitfalls

  • Sampling from the wrong distribution and getting a precise but biased estimate.
  • Using too few trials for the expected variance.
  • Failing to control random seeds for reproducible tests.

Interactive Mechanism Walkthrough

Iterative Convergence & State Trajectory

Show many sampled outcomes accumulating into an estimate.

Monte Carlo Simulation mechanism walkthrough step 1 of 5x₀x₁x₂x*
Step 1 of 5: Define a random experiment
random-trials

Notes

Monte Carlo error usually decreases proportionally to one over the square root of the sample count.

Sources (1)

What each reference supports for this entry.

Metropolis and Ulam 1949

Paper

Foundational paper describing the Monte Carlo method.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Monte Carlo simulation requires pseudorandom samples from a generator.

Monte Carlo integration is a numerical integration use of Monte Carlo simulation.

Tags

SimulationStochasticSamplingRandomness