Monte Carlo answers a question by generating many random versions of the situation and counting what happens. These six small experiments each add one thing the method can do, from two dice to an agent-based model. Drag the sliders, press the buttons, and read the “Try this” box under each one. They accompany a seminar of Social Science Simulations at the University of Tartu; the slides and a Python notebook with the same experiments are linked at the bottom.
Monte Carlo answers a question by generating many random versions of the situation and counting what happens. Every example below, from dice to a city, is built from the same three parts: a model of the situation with something uncertain in it; a random draw that produces one concrete version of that uncertain thing; and repetition and counting, thousands of draws, then a share, an average or a histogram. The average of many draws settles on the true value (the law of large numbers), and the scatter of the estimate shrinks like 1/√N: a hundred times more draws, ten times less scatter.
Each stop ends with a box, Where is the Monte Carlo here?, that names those three parts for that experiment and says what the stop adds to the story. The recipe never changes; only what sits inside the model does, and it grows at every stop.
Roll two dice and add them. How often is the sum 7? The exact answer is 6/36 ≈ 16.7%. The simulation does not know that: it rolls, adds, and counts. Watch how the picture sharpens as you roll more. The histogram and the estimate come from the same rolls: P(7) is simply the height of the middle bar.
Share of each sum: bars = simulated, dots = exact
| Parameter | What it means | What to watch |
|---|---|---|
| Rolls | How many times the two dice are thrown | Bars approach the dots as the number grows. The probability 1/6 itself never changes; what shrinks, roughly like 1/√N, is the scatter of the estimate around it |
| Roll again | A fresh set of random rolls at the same N | At small N each press gives a visibly different picture: the estimate is itself random |
Find the smallest number of rolls at which the estimate stays within one percentage point of 16.7% press after press.
Throw darts at random onto a square with a quarter circle inside. The share that lands inside the circle (inside ÷ thrown) estimates its share of the area, π/4; the circle-area formula then turns that area into π: π ≈ 4 × inside ÷ thrown. Nobody is gambling here: randomness is being used as a ruler.
The board (first 4,000 darts shown)
Running estimate as darts accumulate (dashed = true π)
| Parameter | What it means | What to watch |
|---|---|---|
| Darts | How many random points are thrown at the square | The running estimate wanders, then settles near 3.14 but never becomes exact: always quote a margin |
| Throw again | A fresh set of darts at the same number | Two runs give two different paths and two different final estimates |
| ± two standard errors | The margin computed from the data: 4 × √(p(1−p)/N) × 2, with p the share inside | It needs no knowledge of π, and it shrinks like 1/√N. The actual error is usually inside it. This is the number to report |
How many darts are needed before the estimate is reliably within 0.01 of π? Does the 1/√N rule predict it? The same trick measures the area under any curve; the notebook lets you change the curve.
Polls say 52% will vote yes, but polls miss by about three points and turnout is uncertain too. A single number cannot say whether it passes. Simulate thousands of election nights, each with its own random poll error and turnout effect, and read off a probability and a range.
Final yes share in each simulated election: green = passes, orange = fails
| Parameter | What it means | What to watch |
|---|---|---|
| Polled yes % | What the last polls say | Move it toward 50: the pass probability falls fast near the line |
| Poll error ± | How wrong polls usually are (standard deviation, in points) | Widen it: the histogram flattens and the probability moves toward 50/50 |
| Turnout tilt | Average points gained or lost through turnout | Shifts the whole histogram left or right |
| Simulations | How many election nights are played | At 100 the histogram is ragged; at 10,000 it is smooth |
Find the poll lead at which the pass probability reaches 90%. Then ask: which input would you most want to measure better, the polls or the turnout?
You will compare two groups and expect a modest difference. How many people do you need to detect it? Invent a world where the difference is real, simulate hundreds of fake studies, and count how many of them detect it. That share is the statistical power: the share of whole studies, across many imagined repeats, that detect the effect. The usual target is 80%. The one input you must assume is the effect size d: the difference between the group means divided by the standard deviation of the measurement (0.2 small, 0.5 medium, 0.8 large). The simulation cannot tell you what effect matters; you decide that first.
Power against sample size for this effect size. To read it: follow the line to the dashed 80% target and read the sample size below. Dot = your setting
| Parameter | What it means | What to watch |
|---|---|---|
| People per group | Sample size of each of the two groups | Power rises with n but flattens: going from 100 to 200 buys little for a medium effect |
| Effect size d | How big the real difference is, in standard-deviation units (0.2 small, 0.5 medium, 0.8 large) | Small effects need very large samples; at d = 0.2 the verdict stays red until several hundred per group. Set d = 0: power settles near 5%. With no real effect, one study in twenty still “detects” something: that is the false-alarm rate α |
| Run 400 fresh studies | Repeats the whole batch with new random data | The power moves a little each press: it is itself a Monte Carlo estimate with its own scatter |
For a medium effect, find the smallest group size that reaches 80%. Then press the button several times at that setting and watch the number jitter. The notebook extends this to unequal groups and to checking whether a confidence interval really covers 95%, including two ways to break that check on purpose.
A grid of houses, two kinds of household, one rule: each household has a threshold, the minimum share of its eight neighbours it wants to be its own kind (0.30 means “at least 3 of my 8 like me”), and moves to a random empty house if its street falls below it. The slider calls this “tolerance”, but note that a higher value means a more demanding household. Segregation is measured as the average household's share of similar neighbours: about 0.5 for a mixed city, near 1.0 when fully separated. Schelling (1971) showed that mild thresholds produce strong collective segregation: households stop at 0.30, the city ends near 0.75. One run is an anecdote; the sweep runs the model many times and reveals where the jump is.
One run of the city (40 × 40)
The sweep: segregation against tolerance, averaged over many runs
| Parameter | What it means | What to watch |
|---|---|---|
| Tolerance | Minimum share of similar neighbours a household wants | Clusters appear already at 30%; above about 65% nobody can be satisfied, the city churns and never settles |
| Seed | One seed = one complete random city: the starting arrangement and the order of moves. Like one roll, one dart or one fake study at the earlier stops | Same threshold, different seed: clusters land elsewhere and the segregation number differs. Which run is “the result”? Neither |
| Runs per point | How many seeds are averaged at each threshold in the sweep | More runs: smoother curve, narrower band. In the curve, dots = the estimate, band = the spread, crosses = a single-run anecdote. The loop over seeds is the dice loop of Stop 1; the loop over thresholds is the only new thing |
| Empty share | Fraction of empty houses | More empties make moving easier: does the jump in the curve move? |
Run one city at 30% with three different seeds and note the segregation each time. Then press Sweep and find where the curve jumps. Rule for every agent-based model: never report a single run.
Where agent-based models came from, and where they are going: Ulam, von Neumann and Metropolis, Conway’s Game of Life, Schelling’s 1971 city, Axelrod’s tournaments, and the Santa Fe Institute’s artificial stock market and Sugarscape, are told with pictures in the Santa Fe Institute’s illustrated history Agent-based modeling: worlds within worlds.
Where did Schelling's 30% come from? Nowhere: it stands in for an attitude that real people would report differently, so there is really a distribution of thresholds, not one number. Granovetter (1978) showed how much that matters with a model of a crowd. Each person has a threshold: the share of the others who must already be protesting before this person joins. Some need nobody (they start things), most need a few, some need almost everyone. Each round, everyone whose threshold has been reached joins, and the next round sees a larger crowd. Two crowds with the same average threshold can end in a full riot or in nothing at all, depending only on how much people differ. The left panel shows the crowd's thresholds; the right panel shows what happens.
Granovetter's own example makes the mechanism plain. Imagine 100 people whose thresholds are 0, 1, 2, 3, … up to 99 (each person needs one more than the last). The person with threshold 0 starts; that is one person, which is enough for the person with threshold 1; now two, enough for threshold 2; and so on until all 100 are in. Now change one person: replace the threshold 1 by 2. The starter still starts, but nobody needs exactly one other person any more, so the chain breaks at the first link and the crowd stays at one. Same crowd to within a single person, same average to within a hundredth, and a riot has become nothing. A cascade needs an unbroken ladder of thresholds; spread is what supplies the rungs. That is why a distribution of attitudes, not an average, is what the model needs.
The crowd: how many people have each threshold (1,000 people)
The cascade: share who have joined, round by round (grey = the comparison run)
| Parameter | What it means | What to watch |
|---|---|---|
| Mean threshold | On average, the share of others a person needs to see protesting before joining | Lower means easier cascades, but the mean alone does not decide the outcome |
| Spread (SD) | How much people differ in their thresholds: the width of the histogram | Keep the mean at 0.25 and move the spread slowly from 0.05 upward. At 0.10 almost nobody joins; between about 0.12 and 0.15 the final turnout flips from 0% to 100%, with the average attitude unchanged |
| Compare | Draws the cascade for spread 0.10 and 0.15 together at your mean | Same mean, opposite outcomes. The spark needs a chain: each round must bring enough people whose threshold has just been reached |
| Seed | Which random crowd is drawn from the distribution | Near the flipping point the seed alone can decide the outcome: another reason never to report a single run |
A single number for an attitude cannot capture this; a distribution can. Turning attitudes into numbers (pseudo-quantification) and carrying the uncertainty of that translation into a model is the subject of the next seminar. Three further uses of Monte Carlo, bootstrapping, sensitivity analysis and Markov chain Monte Carlo, are worked through in the notebook.
These experiments accompany a seminar, “Monte Carlo Analysis and Python-based Simulations”, of the course Social Science Simulations (SVUH.00.300) at the University of Tartu, autumn 2026. The slides and a Python notebook with every experiment, its code, sliders and exercises are free to use. The story continues in the From words to numbers tour, which carries the uncertainty of a translated attitude into a model.
Text and figures: CC BY 4.0. Code: MIT. References: Metropolis & Ulam (1949); Metropolis (1987); Schelling (1971); Granovetter (1978); Cohen (1988); Efron (1979).