AI Computer Institute
Expert-curated CS & AI curriculum aligned to CBSE standards. A bharath.ai initiative. About Us

Monte Carlo Methods — Probability as a Computational Tool

📚 Mathematics for AI⏱️ 22 min read🎓 Grade 10
✍️ AI Computer Institute Editorial Team Updated: August 2026 CBSE-aligned · Peer-reviewed · 22 min read
Content curated by subject matter experts with IIT/NIT backgrounds. All chapters are fact-checked against official CBSE/NCERT syllabi.

A Problem Your Probability Formula Cannot Touch

In your CBSE probability chapter, every problem eventually reduces to one line: P(E) = (number of favourable outcomes) / (total number of outcomes). It works beautifully for a die, a deck of cards, a bag of coloured balls — anything where you can sit down and physically list every outcome. Now try this one: you throw a dart at a square board of side 2 units, and it lands at a uniformly random point somewhere inside the square. What is the probability that it lands inside the circle inscribed in that square?

Try applying the classical formula. What is the "total number of outcomes"? The dart can land at literally any point (x, y) with real-number coordinates inside the square — there are infinitely many such points, and worse, they are uncountably infinite, so you cannot even list them one by one the way you list the six faces of a die. The classical definition of probability was built for finite, listable sample spaces. Here it simply has nothing to count. Yet the question is perfectly well-posed and has an exact answer, as you'll see in a moment. We need a genuinely different way of computing probability — one that doesn't count outcomes at all, but instead *samples* them. That technique is called the Monte Carlo method, and by the end of this chapter you will have derived, from first principles, exactly how accurate it is and why it is one of the most-used computational tools in modern science and engineering.

Turning Geometry Into Probability

Place a square of side 2r centred at the origin, so it runs from -r to r on both axes. Inscribe a circle of radius r inside it — the circle touches the midpoint of each side. A point thrown uniformly at random inside the square is equally likely to land anywhere in the square, so the probability that it lands inside the circle is simply the ratio of areas:

P(inside circle) = Area of circle / Area of square = πr² / (2r)² = πr² / 4r² = π/4

This is the exact answer to the "impossible" question above — and notice something remarkable: this probability, which needed no counting of outcomes at all, contains π. That means if we can *measure* this probability experimentally, we can back out an estimate of π. This is exactly the move your Grade 10 chapter calls "experimental probability" — estimate P(E) as (number of trials where E happened)/(total trials), and trust that for a large number of trials this relative frequency approaches the true probability. Monte Carlo methods are experimental probability taken to its full computational extreme: instead of a person tossing a real dart a few dozen times, a computer generates millions of random points in microseconds.

A Small Experiment

Take r = 1, so the square runs from -1 to 1 on both axes and the circle has equation x² + y² ≤ 1. Generate 50 random points (x, y) with each coordinate drawn independently and uniformly from [-1, 1], and check which ones satisfy x² + y² ≤ 1. Here is one such batch, plotted exactly as generated:

Random Sampling: Estimating π Inside circle: 40 points Outside circle: 10 points Estimate: π ≈ 4 × (40/50) = 3.20 (true π = 3.14159…)

Out of 50 points, 40 landed inside the circle. Since P(inside) = π/4, the fraction 40/50 = 0.80 is our estimate of π/4, so π ≈ 4 × 0.80 = 3.20. That's off from the true value 3.14159... by about 0.058 — reasonably close for only 50 throws, but clearly not precise. The natural question, and the one that turns this from a party trick into real mathematics, is: how does the accuracy improve as we throw more points, and can we predict the error before we run the experiment?

The Law of Large Numbers, Derived Properly

Let's set this up formally. Define a random variable for the i-th thrown point:

Xi = 1 if the i-th point lands inside the circle, Xi = 0 otherwise.

Each Xi is a Bernoulli trial with success probability p = π/4 ≈ 0.7854 (exactly the setup of the Binomial distribution you meet in Grade 11-12 statistics — each throw is an independent trial with the same success probability). Our estimator, the fraction of points landing inside, is the sample mean:

p̂ = (X1 + X2 + ... + XN) / N

By linearity of expectation, E[p̂] = (1/N) · N · p = p. So on average, across many repetitions of the whole experiment, our estimator is exactly right — it is unbiased. But we care about how much it varies on any single run of N throws, because that variability is exactly what caused our 50-point estimate to land at 3.20 instead of 3.14159. For that we need the variance.

Each Xi is independent, so variances add:

Var(X1 + ... + XN) = N · Var(Xi) = N · p(1 - p)

(recall Var(Xi) = E[Xi²] - E[Xi]² = p - p² = p(1-p) for a Bernoulli variable — a standard result from your probability distributions chapter). Dividing by N² for the sample mean:

Var(p̂) = Var(X1 + ... + XN) / N² = p(1-p)/N

Taking the square root gives the standard error — the typical size of the gap between our estimate and the truth:

SE(p̂) = √(p(1-p)/N)

This single line is the mathematical heart of Monte Carlo methods. It tells you two things at once. First, as N grows, SE shrinks — this is the Law of Large Numbers in its quantitative form: the sample mean converges to the true mean, and now we know exactly how fast. Second, and more importantly, it shrinks as 1/√N, not as 1/N. Since π̂ = 4p̂, and multiplying a random variable by a constant multiplies its standard deviation by that same constant:

SE(π̂) = 4 · SE(p̂) = 4√(p(1-p)/N)

Plugging in p = π/4 ≈ 0.7854, so p(1-p) ≈ 0.7854 × 0.2146 ≈ 0.1685, and √0.1685 ≈ 0.4105:

SE(π̂) ≈ 4 × 0.4105 / √N ≈ 1.642 / √N

Check this against our 50-point experiment: predicted SE = 1.642/√50 ≈ 1.642/7.07 ≈ 0.232. Our actual error was 0.058 — well inside one standard error, exactly what you'd expect for a single trial. Now watch what happens as N grows:

  • N = 100: SE ≈ 1.642/10 ≈ 0.164
  • N = 10,000: SE ≈ 1.642/100 ≈ 0.0164
  • N = 1,000,000: SE ≈ 1.642/1000 ≈ 0.00164

Notice the pattern: multiplying N by 100 only shrinks the error by a factor of 10. This "square-root law" is the single most important fact about Monte Carlo methods, and it cuts both ways — it is the reason Monte Carlo is comparatively slow to squeeze out extra decimal digits, and, as you'll see two sections from now, the reason it is unbeatable on hard, high-dimensional problems.

Running the Actual Simulation

Here is the method as executable code, with genuinely traced output (Python's Mersenne Twister generator, seeded for reproducibility):

import random

def estimate_pi(n_points):
    inside = 0
    for _ in range(n_points):
        x = random.uniform(-1, 1)
        y = random.uniform(-1, 1)
        if x**2 + y**2 <= 1:
            inside += 1
    return 4 * inside / n_points

for n in [100, 1000, 10000, 100000]:
    random.seed(42)
    print(n, estimate_pi(n))

# Output:
# 100   3.2
# 1000  3.18
# 10000 3.1392
# 100000 3.14028

Line by line: random.uniform(-1, 1) draws a real number uniformly from [-1, 1] for each coordinate — this is the computer equivalent of "throw the dart uniformly." The condition x**2 + y**2 <= 1 is precisely x² + y² ≤ 1, our circle test with r = 1. inside/n_points is p̂, and multiplying by 4 gives π̂, exactly the formula we derived. Look at the actual run: at N = 10,000 the estimate is 3.1392, an error of about 0.0024 — comfortably inside the predicted SE of 0.0164. At N = 100,000 the estimate is 3.14028, error about 0.0013, inside the predicted SE of 0.0052. The theory and the code agree.

Beyond Circles: Monte Carlo Integration

The circle-in-square trick looks like a geometry party piece, but it is a special case of something far more general and far more useful: estimating any definite integral using randomness. Suppose you need ∫ab f(x) dx for a function f that has no elementary antiderivative — a real, common situation once you go past the AI-friendly polynomial and trigonometric integrals of the Grade 12 calculus syllabus. The classic example is the Gaussian integral ∫01 e-x² dx, which shows up whenever you touch the normal distribution (statistics, JEE probability, physics error analysis) and provably cannot be written using elementary functions.

Here's the bridge from probability to integration. If X is a random variable uniformly distributed on [a, b], its probability density function is the constant 1/(b - a) on that interval. The expected value of f(X) is, by definition:

E[f(X)] = ∫ab f(x) · (1/(b-a)) dx = (1/(b-a)) ∫ab f(x) dx

Rearranging, the integral we actually want is:

I = ∫ab f(x) dx = (b - a) · E[f(X)]

And by exactly the same Law of Large Numbers argument as before, we can estimate E[f(X)] by the sample average of f at N uniformly random points x1, ..., xN in [a, b]:

Î = (b - a) · (1/N) Σ f(xi)

The circle-in-square estimator you derived earlier is the special 2-dimensional case of exactly this idea, with f being the indicator function "is this point inside the circle." Now apply the general formula to our Gaussian integral, with a = 0, b = 1, f(x) = e-x²:

import random, math

def mc_integral(n):
    total = 0.0
    for _ in range(n):
        x = random.uniform(0, 1)
        total += math.exp(-x * x)
    return total / n   # (b-a) = 1, so this already equals the estimate

for n in [1000, 10000, 100000]:
    random.seed(7)
    print(n, mc_integral(n))

# Output:
# 1000   0.7585213342735750
# 10000  0.7477795932958295
# 100000 0.7475022095941349
#
# True value (via the error function): 0.7468241328124269

The true value 0.746824... comes from the closed form √π · erf(1) / 2, where erf is the error function you may meet later in calculus — but notice we never needed to know that closed form, or even that it existed, to compute an accurate estimate. That is the entire power of the method: Monte Carlo integration does not care whether an antiderivative exists. It only needs you to be able to evaluate f(x) at points, which you almost always can.

Why High-Dimensional Problems Need This

Here is the payoff for the 1/√N law that looked like a weakness earlier. Suppose instead of a 1-dimensional integral, you need to estimate an integral over a d-dimensional region — d = 6 for a problem in 3D physics with 3 momentum and 3 position variables, easily d = 50 or more in financial risk models with many correlated assets. A grid-based method (evaluate f on a regular grid of m points per axis, like a very fine graph paper) needs md total evaluations, because you must cover every axis in every combination. At m = 10 points per axis and d = 10 dimensions, that is 1010 — ten billion evaluations, for a fairly coarse grid.

Monte Carlo integration does not have a grid. The error formula SE ∝ 1/√N (with a constant that depends on the variance of f, not on d) is essentially the same regardless of how many dimensions the region has — you are always just averaging N independent samples of a single number, f(xi). This is why Monte Carlo methods, not grid methods, are the default tool the moment a problem has more than a handful of dimensions: the "curse of dimensionality" that cripples grid-based numerical integration barely touches random sampling.

Correcting a Common Misconception

A very natural but wrong reaction to all of this is: "It uses random numbers, so the answer is unreliable — real mathematics should give an exact, repeatable answer." This gets the situation backwards. We did not wave our hands and hope; we derived SE(π̂) = 4√(p(1-p)/N) rigorously from the variance of a Bernoulli sum. That formula tells you, before you even run the code, exactly how large the error is likely to be for a given N, and you can drive that error as low as your computing budget allows by increasing N. That is a stronger, more honest guarantee than many "exact" numerical methods offer, which often come with error bounds that are difficult to compute or depend on unknown smoothness properties of f. Monte Carlo trades a small, precisely quantified randomness for the ability to solve problems — high-dimensional integrals, complex simulations with no closed form — that no exact method can touch at all.

A second, more technical misconception: the numbers generated by random.uniform() are not truly random. They come from a deterministic algorithm called a pseudo-random number generator (Python uses the Mersenne Twister), which starts from a "seed" and produces a long, statistically well-mixed sequence. That's precisely why random.seed(42) in the code above makes the output exactly reproducible — a genuinely random process could never be replayed like that. For Monte Carlo purposes this sequence behaves indistinguishably from true randomness (it passes rigorous statistical tests), which is all the mathematics above actually requires.

Where This Is Actually Used

The method takes its name from the Monte Carlo casino in Monaco — physicist Nicholas Metropolis suggested the name in the 1940s, referencing his colleague Stanislaw Ulam's uncle, who gambled there. Ulam and John von Neumann developed the technique at Los Alamos National Laboratory to estimate neutron diffusion through fissile material for the Manhattan Project — a problem with far too many interacting particles and collision angles for any exact formula, but perfectly suited to simulating many random neutron paths and averaging the outcomes.

The same core idea now runs in very different-looking places. Photorealistic rendering in film and games (path tracing) estimates the light-transport integral — how much light reaches a camera pixel after bouncing around a scene — by tracing thousands of random light paths per pixel and averaging, because that integral has no closed form for a complex 3D scene. Particle physics experiments simulate what a detector should see for a given theoretical model by generating millions of random particle collisions and comparing the simulated data to what was actually recorded. Aerospace engineers run trajectory dispersion analysis — simulating a launch or re-entry thousands of times with small random variations in wind, thrust, and sensor error — to estimate the probability that a vehicle lands within a safe corridor, since the coupled differential equations of flight with realistic random disturbances have no clean analytical solution. Cricket broadcasters' live win-probability numbers are typically produced the same way: the model simulates the remainder of the match ball-by-ball thousands of times using realistic per-ball outcome probabilities, and the displayed win percentage is simply the fraction of those simulated matches the batting side won — a direct descendant of the circle-in-square experiment you just derived, applied to twenty-two players instead of two coordinates.

Where This Sits in Your Exams

For CBSE Boards, this chapter is the natural extension of the Probability chapter's distinction between classical and experimental (empirical) probability — expect conceptual questions on why experimental probability approaches the classical value as trials increase, which is exactly the Law of Large Numbers argument you derived above, minus the variance formula. For JEE Main/Advanced and BITSAT, the Bernoulli trial and variance derivation (Var(X) = p(1-p), variance of a sum of independent variables) is standard Probability Distributions syllabus and appears directly in binomial-distribution problems; recognizing "estimate via repeated random trial" as the same machinery is a genuine edge in unfamiliar applied-probability questions. For KVPY and Olympiad-style problems, geometric probability (the π/4 area-ratio argument) is a recurring problem type independent of any programming context — the area/measure argument you used to get p = π/4 is the general technique for continuous sample spaces. For a GATE-foundation track, Monte Carlo integration and the curse of dimensionality are core numerical-methods and computational-science topics you will meet again, unchanged, at the undergraduate level.

Active Recall

1. A Monte Carlo π-estimation experiment uses N = 2,500 random points. Using SE(π̂) ≈ 1.642/√N, what standard error do you expect? (Answer: 1.642/√2500 = 1.642/50 ≈ 0.0328.)

2. How many points N are needed to bring the expected error below 0.001? (Answer: solve 1.642/√N = 0.001 ⇒ √N = 1642 ⇒ N = 1642² ≈ 2.70 million points — illustrating how expensive high precision is under the 1/√N law.)

3. If you double the number of sample points, by what factor does the standard error shrink? (Answer: by a factor of √2 ≈ 1.414, not by 2 — because SE ∝ 1/√N, not 1/N. To actually halve the error you must quadruple N.)

4. Derive Var(p̂) yourself for a general Bernoulli mean estimator based on N independent trials each with success probability p, without looking back at the chapter. Then check it reduces to p(1-p)/N.

5. A satellite image gives you a rectangle of known area A that fully contains an irregularly shaped lake. You can test whether any given pixel coordinate falls inside the lake (by colour) or not. Describe, in one or two sentences, how you would estimate the lake's area using the ideas in this chapter, and state what quantity in your estimate corresponds to p = π/4 from the circle experiment. (Answer: throw N uniformly random points in the rectangle, let p̂ be the fraction landing inside the lake, and estimate lake area ≈ A × p̂; here p̂ estimates the true ratio (lake area)/(rectangle area), playing exactly the role π/4 played for the circle.)

Summary

Classical probability needs a finite, listable sample space; Monte Carlo methods handle continuous and combinatorially enormous sample spaces by sampling instead of counting, then leaning on the Law of Large Numbers. The circle-in-square experiment showed this concretely: P(inside) = π/4 by an area argument, and the sample fraction p̂ is an unbiased estimator whose variance we derived exactly as p(1-p)/N, giving standard error SE(π̂) = 4√(p(1-p)/N) ≈ 1.642/√N. That 1/√N convergence rate is the defining signature of every Monte Carlo method, verified against real traced code output at N = 100 through 100,000. The same expectation argument generalizes the circle trick into full Monte Carlo integration, Î = (b-a)·(1/N)Σf(xi), letting you estimate integrals like ∫e-x²dx that have no elementary antiderivative. Because the error formula never mentions the dimension of the problem, Monte Carlo methods sidestep the curse of dimensionality that cripples grid-based numerical methods, which is precisely why they underpin neutron transport at Los Alamos, light transport in film rendering, aerospace trajectory-dispersion analysis, and live cricket win-probability models today — all genuine descendants of throwing points at a circle inside a square.

Practice Exercises

Now it is time to practice! Complete these challenges to solidify your understanding:

  • Exercise 1: Write a short program that demonstrates the core concept from this chapter. Test it with at least 3 different inputs.
  • Exercise 2: Find a real-world example where monte carlo methods — probability as a computational tool is used in an Indian company (like TCS, Infosys, Flipkart, or ISRO). Write a paragraph explaining the connection.
  • Exercise 3: Create a mind-map connecting monte carlo methods — probability as a computational tool to at least 3 other topics you have studied.
← Information Retrieval and Search SystemsThe Expectation-Maximization Algorithm →

Found this useful? Share it!

📱 WhatsApp 🐦 Twitter 💼 LinkedIn