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

Monte Carlo: Learning Through Random Sampling

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

A Courtyard, the Rain, and a Circle

Picture a square courtyard, four metres on each side, with a circular rangoli drawn at its centre so that the circle just touches all four sides. It starts to rain, hard and evenly, so that raindrops land at completely random points across the whole courtyard — no drop is more likely to fall near the centre than near the corners. You want to know one thing: what fraction of the courtyard's area does the circular rangoli cover?

You already know a formula for this — area of circle over area of square — but suppose, for a moment, that you didn't. Suppose the rangoli's outline were some irregular hand-painted shape with no clean formula at all. You could still answer the question without any formula, just by standing at the gate and counting: count every drop that lands inside the shape, count every drop that lands anywhere in the courtyard, and divide. If a thousand drops fall and 780 of them land inside the shape, your best guess is that the shape covers about 78% of the courtyard. Rain more, count longer, and your guess gets steadily more trustworthy.

That single idea — replace a hard-to-compute quantity with the fraction of random samples that satisfy some condition — is the entire engine behind a family of techniques called Monte Carlo methods. They sound exotic, but you have just derived the core of one from a courtyard and some rain. This chapter turns that intuition into a precise, provable, and genuinely useful piece of mathematics: precise enough to derive its own error bars, and useful enough that it estimates neutron behaviour inside a nuclear reactor, prices financial derivatives, renders the lighting in animated films, and lets a computer program teach itself to play Go better than any human.

What Exactly Is a Monte Carlo Method?

A Monte Carlo method is any technique that estimates a numerical answer — an area, a probability, an average, an integral — by generating a large number of random samples and computing a statistic (usually a simple average or a fraction) over those samples, rather than by solving the problem exactly with algebra or geometry. It trades exactness for tractability: instead of an exact formula that might be impossible to write down, you get an estimate that gets more accurate the more samples you draw, and — this is the part most people miss — you can calculate in advance exactly how accurate it will probably be.

The name has a specific, well-documented origin. In 1946, the mathematician Stanisław Ulam, recovering from an illness at Los Alamos National Laboratory, was playing solitaire and wondered about his odds of winning a particular deal. Counting every possible arrangement of the cards was hopelessly complicated, but he realised he could get a good answer far more easily: lay out a hundred random games and see what fraction he won. He described the idea to John von Neumann, and the two of them saw immediately that the same trick could attack a problem far more consequential than solitaire — predicting how neutrons scatter and multiply as they pass through fissile material, a calculation with no clean closed-form solution but one that could be approximated by simulating the random paths of many individual neutrons and averaging the outcomes. Their colleague Nicholas Metropolis suggested the code name "Monte Carlo," after the casino in Monaco where Ulam's uncle used to borrow money to gamble. The name stuck, and by the early 1950s the method was running on one of the world's first electronic computers, ENIAC.

The Rangoli Experiment, Formalised

Let's turn the courtyard into coordinates. Place the square so it runs from −1 to 1 along both the x-axis and the y-axis. Its side length is 2, so its area is 2 × 2 = 4. Draw a circle of radius 1 centred at the origin, exactly inscribed in the square — it touches the midpoint of each side. The circle's area, by the standard formula, is πr² = π(1)² = π.

Now the ratio of the two areas is

(area of circle) ÷ (area of square) = π ÷ 4

Here is the move that makes this a Monte Carlo method: if you scatter points uniformly at random inside the square, the probability that any single point also lands inside the inscribed circle is exactly that same ratio, π/4, because "uniformly random inside a region" means every equal-area patch of the region is equally likely to catch the point. So if you generate N random points inside the square, count how many, call it k, land inside the circle (satisfying x² + y² ≤ 1), then k/N is an estimate of π/4, and therefore

π ≈ 4 × (k / N)

This is not a coincidence or an approximation trick specific to circles — it is the general Monte Carlo recipe for estimating an area or a probability: (1) define a region you can sample uniformly and easily, (2) define a yes/no test for the quantity you actually care about, (3) sample many points, (4) take the fraction that pass the test, and (5) rescale by whatever known area or probability your sampling region corresponds to.

Estimating π from 10 random points inside circle (7 points) outside circle (3 points) estimate = 4 × (7/10) = 2.8  (true π = 3.14159…) only 10 samples → large error; more samples will close the gap

Tracing the Algorithm By Hand

Before trusting a computer to run this thousands of times, trace it yourself on ten points, so you can see exactly what the computer will be doing. For each point (x, y), the test is x² + y² ≤ 1. Here are ten sample points (chosen to illustrate the arithmetic clearly, the same ten shown in the diagram above), with the test worked out for each:

  1. (0.3, 0.4): 0.09 + 0.16 = 0.25 ≤ 1 → inside
  2. (0.9, 0.9): 0.81 + 0.81 = 1.62 > 1 → outside
  3. (−0.5, 0.2): 0.25 + 0.04 = 0.29 ≤ 1 → inside
  4. (0.95, −0.1): 0.9025 + 0.01 = 0.9125 ≤ 1 → inside
  5. (−0.8, −0.8): 0.64 + 0.64 = 1.28 > 1 → outside
  6. (0.1, −0.99): 0.01 + 0.9801 = 0.9901 ≤ 1 → inside
  7. (0.7, 0.7): 0.49 + 0.49 = 0.98 ≤ 1 → inside
  8. (−0.99, 0.3): 0.9801 + 0.09 = 1.0701 > 1 → outside
  9. (0.0, 0.95): 0 + 0.9025 = 0.9025 ≤ 1 → inside
  10. (0.6, −0.6): 0.36 + 0.36 = 0.72 ≤ 1 → inside

Seven of the ten points land inside the circle, so k = 7 and N = 10, giving π ≈ 4 × 7/10 = 2.8. That is a poor estimate — off by about 0.34 from the true value 3.14159… — and that is expected and instructive: ten samples is a tiny amount of evidence, exactly like judging a coin fair or biased after only ten tosses. The fix is not a different formula; it's more rain.

Code: Doing It at Machine Scale

A computer can generate and test millions of points in the time it takes you to test one by hand. Here is the algorithm above, written directly from the same recipe — sample a point, test it, count, rescale:

import random

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

print(estimate_pi(1_000_000))

Every line maps to a step you already traced by hand: random.uniform(-1, 1) draws a coordinate uniformly from the square's range for that axis, so the pair (x, y) is a uniformly random point in the square; the if statement is exactly the test x² + y² ≤ 1; inside plays the role of your tally of "inside" points; and the final line is the rescaling step, 4 × k/N. Because random.uniform draws a genuinely different sequence of numbers on every run (it uses a pseudo-random number generator seeded from unpredictable system state, unless you deliberately fix a seed), running this function twice will not give identical outputs — but with a million samples both runs will land close to 3.14159, typically agreeing on the first two or three decimal digits. That "typically" is not a vague hedge; the next section derives exactly how close "typically" means.

Why Does This Even Work? The Law of Large Numbers

The justification is a theorem called the Law of Large Numbers: if you repeat an experiment N times independently, the observed fraction of times an event occurs converges to the event's true probability as N grows without bound. This is precisely the statement your probability chapter already makes when it says that experimental (or empirical) probability approaches theoretical probability as the number of trials becomes very large — Monte Carlo estimation is that exact idea, deliberately engineered into an algorithm. The "experiment" is dropping a random point in the square; the "event" is landing inside the circle; the "true probability" is π/4; and running the experiment a million times instead of ten is simply taking the phrase "very large number of trials" seriously.

How Good Is the Estimate? Deriving the Error

Saying an estimate "gets better with more samples" is not enough — a rigorous method should tell you how much better, in advance. This is where Monte Carlo methods earn their scientific credibility: unlike a random guess, the uncertainty is fully computable.

For each sample point i, define an indicator variable Xi, equal to 1 if that point lands inside the circle and 0 otherwise. Each Xi takes the value 1 with probability p = π/4 and 0 with probability 1 − p, so its expected value is E[Xi] = p. Because Xi only ever takes the values 0 or 1, Xi² equals Xi itself, so E[Xi²] = p too. The variance of Xi is then

Var(Xi) = E[Xi²] − (E[Xi])² = p − p² = p(1 − p)

Your estimator for p is the sample mean, p̂ = (1/N) Σ Xi. Since the samples are independent, variances of independent sums add, and dividing a sum by N divides its variance by N²:

Var(p̂) = (1/N²) × N × p(1 − p) = p(1 − p) / N

Your π estimate is 4p̂, and scaling a random variable by a constant c scales its variance by c², so Var(4p̂) = 16 × p(1−p)/N. The standard error (the typical size of the gap between your estimate and the true value) is the square root of the variance:

SE = 4 × √(p(1−p) / N)

Plugging in p = π/4 ≈ 0.7854, so p(1−p) ≈ 0.1685, gives SE ≈ 4 × √(0.1685/N) ≈ 1.642 / √N. Check this against your two examples: at N = 10, SE ≈ 1.642/√10 ≈ 0.519, and your hand-traced estimate of 2.8 was off by 0.34 — comfortably inside one standard error, exactly the kind of result you'd expect from a small, noisy sample. At N = 1,000,000, SE ≈ 1.642/1000 ≈ 0.0016, so the Python code above will typically land within about 0.0016 of 3.14159… — matching the "first two or three decimal digits" claim made earlier, now with a derivation behind it instead of a hand-wave.

If this formula looks familiar, it should: for N independent trials of an event with probability p, the number of successes follows a Binomial(N, p) distribution with variance Np(1−p) — the "npq" variance formula that appears directly in the CBSE/JEE statistics and probability-distribution syllabus. The Monte Carlo error bound above is nothing but that formula, rescaled to the estimator you actually care about.

Common misconception, worth stating explicitly: because SE is proportional to 1/√N and not 1/N, doubling your sample size does not halve your error. To cut the standard error in half, you must quadruple N; to shrink it by a factor of 10, you need 100 times as many samples. This is why Monte Carlo methods are powerful but not magic — pushing an estimate from three correct decimal digits to six correct decimal digits costs roughly a million times more computation, not a thousand times more. It's also why a second, separate misconception is worth killing here: a Monte Carlo method never claims to produce the exact answer, even in principle, for a fixed finite N — it produces a random estimate with a quantifiable spread around the true answer, which is a fundamentally different (and, for problems with no exact formula, often the only available) kind of correctness.

A Second Flavour: Simulating a Probability Problem

The circle-and-square example estimates a geometric ratio, but the same machinery estimates probabilities of events directly, with no geometry at all. Take a classic CBSE-style probability question: a fair six-sided die is rolled 4 times; what is the probability of getting at least one six?

The exact route uses the complement rule. The probability of not rolling a six on a single roll is 5/6, and the four rolls are independent, so the probability of getting no six at all in four rolls is (5/6)4 = 625/1296 ≈ 0.4823. The probability of at least one six is the complement of that:

P(at least one six) = 1 − 625/1296 = 671/1296 ≈ 0.5177

Now simulate the same question instead of reasoning about it:

import random

def simulate_at_least_one_six(trials):
    hits = 0
    for _ in range(trials):
        rolls = [random.randint(1, 6) for _ in range(4)]
        if 6 in rolls:
            hits += 1
    return hits / trials

print(simulate_at_least_one_six(100_000))

Each pass of the loop rolls four dice, checks whether a six shows up anywhere among them, and tallies a hit if so — the fraction of hits after 100,000 trials is a Monte Carlo estimate of P(at least one six), and by the same standard-error reasoning as before (here p ≈ 0.5177, p(1−p) ≈ 0.2497, SE = √(0.2497/100000) ≈ 0.0016) it should land within about 0.0016 of 0.5177 — again typically matching to three decimal places. The value of running both the exact calculation and the simulation side by side is not that the simulation is "needed" here — the exact formula is easy — but that agreement between them is a trustworthy way to check your exact reasoning, and a rehearsal for the much more common situation where no clean formula like (5/6)4 exists at all.

Where This Powers Real Systems

The reason Monte Carlo methods matter beyond the classroom is that most interesting real-world quantities do not have a clean formula. A neutron bouncing through a reactor core, a stock price buffeted by market noise, or a ray of light bouncing between surfaces in a rendered 3D scene all involve too many interacting random variables for exact integration to be feasible — but each is easy to simulate one random instance at a time and then average over many instances, exactly like the die and the rangoli. Financial engineers price complex options this way when no closed-form pricing formula exists; special-effects and animation studios use Monte Carlo path tracing to compute how light scatters through a scene, averaging over huge numbers of randomly sampled light paths to render a realistic image; and aerospace engineers use it to estimate the probability that a spacecraft component survives re-entry given many small, randomly varying manufacturing tolerances, none of which can be pinned down exactly in advance.

There is also a direct line from this chapter's title to modern artificial intelligence. In problems with astronomically large possibility spaces — the game of Go has been estimated to have more than 10170 legal board positions, far more than a computer could ever enumerate — an AI agent cannot compute the exact best move by exhaustive search. Instead, algorithms called Monte Carlo Tree Search estimate how good a move is by simulating many random "playouts" from that position to the end of the game and averaging the outcomes, exactly as your estimate of π averaged the outcomes of many random points. DeepMind's AlphaGo, which defeated top professional Go player Lee Sedol in 2016, combined Monte Carlo Tree Search with deep neural networks that guided which random playouts were worth simulating. The phrase "learning through random sampling" is literal here: the system's evaluation of a position is, at its core, an average over randomly sampled futures, refined the same way your π estimate refined itself — by sampling more.

Exam Angle: CBSE, JEE, and Beyond

Monte Carlo methods themselves are not a named CBSE board-exam topic, but the mathematics underneath them is examined directly, and understanding this chapter strengthens exactly those areas. The convergence of experimental probability to theoretical probability with increasing trials is stated explicitly in the CBSE Probability chapter and is a favourite source of conceptual (not just numerical) board questions. The variance derivation above — Var(X) = E[X²] − (E[X])² for a Bernoulli variable, and Var = npq for a Binomial — is core JEE Main and JEE Advanced syllabus under Probability Distributions and Statistics, and appears regularly in both direct-computation and reasoning-based questions. For BITSAT and GATE-foundation preparation, the same simulate-and-average pattern reappears as a standard technique in computational thinking and algorithm-design questions. And in KVPY and Olympiad-style problem sets, the habit this chapter builds — being able to say not just "here is my estimate" but "and here is exactly how wrong it is expected to be" — is precisely the kind of quantitative rigour those examinations reward over a guess stated with false confidence.

Check Your Understanding

  • You run the estimate_pi function with N = 40,000 samples and get k = 31,420 points inside the circle. What is your π estimate, and using the standard-error formula SE ≈ 1.642/√N, is this estimate within one standard error of the true value of π?
  • Two students each run the die-rolling simulation with 100,000 trials and get slightly different answers, 0.5183 and 0.5169. Explain, using the Law of Large Numbers and the standard-error formula, why this disagreement is expected and is not a bug in either student's code.
  • A classmate says: "I ran 10,000 samples and got a poor estimate, so next time I'll run 20,000 samples to fix it." Using the 1/√N scaling derived in this chapter, explain precisely how much the error is expected to shrink, and how many samples would actually be needed to cut the original error in half.
  • Redesign the rangoli experiment to estimate the area of a shape that is a circle of radius 1 minus a smaller circle of radius 0.5 cut out of its centre (a ring, or annulus), still using a square of side 2 as your sampling region. What is the new test condition for a point (x, y) to count as "inside," and what is the exact theoretical value of (area of ring)/(area of square) that your simulation should converge to?

Summary

  • A Monte Carlo method estimates a hard-to-compute quantity by drawing many random samples, testing each against a simple condition, and rescaling the fraction that pass — the same logic as counting raindrops inside a shape in a courtyard.
  • The method is named after the Monte Carlo casino, following Stanisław Ulam's 1946 realisation (while considering solitaire odds) that random sampling could replace an intractable exact calculation; he and John von Neumann first applied it to neutron diffusion at Los Alamos.
  • Estimating π by sampling random points in a square and checking whether they land inside an inscribed circle works because a uniformly random point lands inside the circle with probability exactly π/4, so π ≈ 4 × (points inside)/(total points).
  • The method's validity rests on the Law of Large Numbers: the observed fraction of "successes" converges to the true probability as the number of trials grows, the same principle behind experimental probability approaching theoretical probability.
  • The error is not hand-waved but derived: because each sample behaves like a Bernoulli variable with variance p(1−p), the standard error of a Monte Carlo estimate scales as 1/√N — meaning you must quadruple your sample size to halve your error, not merely double it.
  • The same sample-test-average pattern estimates probabilities directly (as with the dice example), and scales up to real systems with no exact formula at all: nuclear reactor physics, financial option pricing, photorealistic rendering, aerospace reliability, and Monte Carlo Tree Search in AI systems like AlphaGo.

Think About It

Think about this: How would you explain monte carlo: learning through random sampling to a friend who has never seen a computer? What real-world analogy would you use? Imagine you had to build a system using these concepts — what would be your first step? Try this: before moving on, write down three things you learned and one question you still have.

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: learning through random sampling 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: learning through random sampling to at least 3 other topics you have studied.
← Markov Chains: Future Only Depends on NowHidden Markov Models: Seeing Through Noise →

Found this useful? Share it!

📱 WhatsApp 🐦 Twitter 💼 LinkedIn