On this concept: Formula

Not sure which lesson to do first? Find your level and get a plan →

CS Thinking · Computational Thinking · Grade 6-8

Simulation

Using a computer program to model and experiment with a real-world system or process: simulations track key variables and their relationships so you can test scenarios, make predictions, and explore outcomes without real-world cost or risk.

St+1=f(St,P)

Quick Answer

Using a computer program to model and experiment with a real-world system or process: simulations track key variables and their relationships so you can test scenarios, make predictions, and explore outcomes without real-world cost or risk. A simulation keeps a state (the numbers describing the system right now) and a rule that turns this step's state into the next one, then repeats. Use one when the real experiment is too slow, costly or dangerous: a rumor spreading through a school, a bridge in an earthquake, tomorrow's weather.

Why This Matters

A simulation lets you ask 'what if?' as many times as you like: what if 60% of people are vaccinated, what if the road gets a third lane? Pilots train in simulators because a crash there costs nothing. But the answers are only as good as the rules, and a model that has never been checked against real data can produce precise-looking numbers that are wrong.

Intuitive Explanation

Start with a pond of 100 fish that grows by 10% a year. A simulation stores the state, fish = 100, and a rule: next year's fish = this year's fish × 1.1. Run the rule once: 110. Again: 121. Again: 133.1, so about 133 fish after 3 years. Each step uses the previous step's answer, which is why the general form is St+1=f(St,P): the next state comes from the current state and some settings P, here the growth rate.

The power is in changing the settings. Add a rule that people catch 15 fish a year and run it again: 100, then 95, then 89.5, then 83.45. The pond now shrinks instead of growing. Trying that on a real pond would take years and might empty it; the program takes a second.

Every simulation leaves things out: weather, food supply, the fact that fish come in whole numbers. Choosing what to keep is abstraction, and it is why a simulation has to be checked against reality before anyone trusts it. Small errors also grow. If the real growth rate is 8% instead of 10%, the 3-year prediction of 133 is about 7 fish too high, and the gap widens every year.

Not every program with numbers is a simulation. A program that averages your test scores computes a fact about data you already have. A simulation imitates a system that changes, one step at a time.

Think of it like this. A simulation is a flight simulator for any system: a cockpit where nothing can really crash, so you can try a storm, an engine failure or a bad landing as often as you like. What you learn carries over only if the simulator's physics match the real plane closely enough.

Core idea. Simulations simplify reality by choosing which variables to model and which details to ignore.


When to Use

Use a simulation when a real system changes over time and you want to predict what happens or compare what if scenarios: crowds leaving a stadium, a disease spreading, a ball's flight, a population of animals. It is the right tool when the real experiment would be slow, costly or dangerous. If you are writing steps to solve a problem with no real system being imitated, that is an Algorithm. If the main question is which details to leave out, that is Abstraction.

Tip. Ask: Does a program apply an update rule over and over, one time step at a time, to show how a system changes?

How to Recognize It

Look for a model being run forward in time, with numbers that change at each step.

  1. Is there a state, such as how many people are sick or where a ball is, that gets updated step after step?

    Yes points to simulation. If the task stops at choosing which quantities to include and writing the rule, without running it, that is Modeling.

  2. Would the real experiment be too slow, costly or dangerous to try directly?

    Yes is the usual reason to simulate. If you can simply calculate the answer once with a fixed set of steps, a plain Algorithm does the job.

  3. Are chance events, like whether a coin lands heads, decided inside the run?

    Yes means the simulation uses random numbers as one ingredient. If the whole task is producing a single chance value, such as one die roll, it is about Random Numbers.

  4. Is the question about what happens over many steps, rather than which details to leave out?

    Yes keeps you at simulation. If it asks which details of the real thing to drop, such as the color of each car, that is Abstraction.

Simulation vs Modeling vs Random Numbers vs Abstraction

A simulation is built from a model, often uses random numbers and always involves abstraction, so the ideas travel together. Ask whether you are running something forward in time or preparing one of its parts.

Simulation

Meaning
A simulation runs a model of a real system step by step on a computer to see what would happen.
Key test
Something is run forward through time steps while you watch the numbers change.
Formula
St+1=f(St,P)
Example
Running a flu model for 30 simulated days to see when the most students are sick at once.

Modeling

Meaning
Modeling is building the simplified description of a system, its quantities and rules, before anything is run.
Key test
You are deciding what to include and how it behaves, not running it yet.
Formula
output=f(inputs,assumptions)
Example
Deciding a flu model needs counts of healthy, sick and recovered students, and a daily infection rate.

Random Numbers

Meaning
Random numbers are values picked by chance, often by a seeded formula, that a program can use for unpredictable events.
Key test
The focus is one chance value or its fairness, not a whole system.
Formula
P(r=i)=1n
Example
Picking a number from 1 to 100; if it is 5 or less, that student catches the flu today.

Abstraction

Meaning
Abstraction is choosing which details of a problem matter and hiding the rest.
Key test
You are throwing details away, with or without any computer involved.
Example
A subway map keeps the stations and their order but drops the real distances and street names.

Formula & Notation

St+1=f(St,P)
A simulation defines a model M with state variables S=(s1,s2,…,sk) and update rules St+1=f(St,P) parameterized by P, iterated over discrete time steps to approximate real-world dynamics.

Worked Examples

Example 1 — Run a rumor simulation

Easy

A school has 400 students. On day 0, 5 students know a rumor. In this model, each day every student who knows it tells 2 students who have not heard it yet. Simulate day by day. On which day does the whole school know?
Show the steps and the answer
  1. Set the state: day 0, knowers = 5.

    The state is the one number this model tracks; everything else about the school is left out.

  2. Write the rule: each day, knowers = knowers + 2 × knowers = 3 × knowers, but never more than 400.

    Each knower adds 2 new people, and there are only 400 students to tell.

  3. Run it: day 1: 15; day 2: 45; day 3: 135; day 4: 3 × 135 = 405, capped at 400.

    Each day's state is computed from the day before, so the steps must be done in order.

  4. Read the prediction: after day 3, 400 − 135 = 265 students still have not heard; by day 4 everyone has.

    The answer is whatever the state has become when the question's condition is first met.

Answer: 5, 15, 45, 135, then all 400 students on day 4.

Takeaway: A simulation is a state plus a rule applied again and again; its prediction is whatever the state turns into.

Example 2 — Calculation or simulation?

Standard

Program A reads last month's 30 daily rainfall readings and prints the total, 84 mm. Program B starts a reservoir at 500 million litres and, each day, adds that day's rain and subtracts the town's use, to predict when the level will fall below 200 million litres. Which is a simulation? Run B for 3 days with 10, 0 and 5 million litres of rain and 40 million litres of use per day.
Show the steps and the answer
  1. Look at Program A: it adds 30 recorded numbers once and stops.

    A summarizes what already happened. No state is updated by a rule, so it is a calculation, not a simulation.

  2. Look at Program B: its state is the water level, and its rule is level = level + rain − use, repeated day after day.

    B imitates a real system as it changes over time, which is what makes it a simulation.

  3. Run B: day 1: 500 + 10 − 40 = 470; day 2: 470 + 0 − 40 = 430; day 3: 430 + 5 − 40 = 395 million litres.

    Each day starts from the level the day before ended at.

  4. Ask 'what if': with use cut to 30 million litres a day, day 3 ends at 500 + 15 − 90 = 425 million litres.

    Changing one setting and re-running is the experiment the town cannot safely try on the real reservoir.

Answer: Program B is the simulation. It predicts 395 million litres after 3 days, or 425 million if daily use drops to 30 million. Program A is a calculation on recorded data.

Takeaway: A simulation has a state that a rule updates step after step. A program that only summarizes recorded data is not one.

Example 3 — Find the mistake: trusting an unchecked model

Application

Ben's simulation of a pond starts with 200 frogs and multiplies by 1.5 each year, predicting 300 after one year and 450 after two. A real count after one year finds 260 frogs. Ben writes: "The computer did the math, so the count must be wrong, and next year there will be 450." Find the mistake and correct it.
Show the steps and the answer
  1. Compare the model with the count: it predicted 300 frogs after one year; the count found 260.

    Checking a prediction against something you can measure is the only way to know whether the rule matches reality.

  2. Work out the real growth: 260 ÷ 200 = 1.3, so the frogs grew by 30%, not 50%.

    The gap comes from the rule, not the arithmetic. The computer applied a wrong growth factor perfectly.

  3. Fix the model: start from the real count, 260, and use × 1.3: next year 260 × 1.3 = 338.

    Restarting from measured data with a measured rate removes the error that had already built up.

  4. Compare with Ben's 450: the old rule is 450 − 338 = 112 frogs too high after only two years.

    Errors in a rule compound, because every step multiplies the previous step's mistake.

Answer: Ben trusted a rule he never checked. With the measured growth of 30% and the real count of 260, the model predicts about 338 frogs next year, not 450.

Takeaway: Check a simulation against real measurements before trusting it, and change its rules when they disagree.

Where You'll See It

  • Weather forecast app

    The forecast comes from a simulation that models air pressure, temperature, and wind over time to predict tomorrow's weather without waiting for it to actually happen.

  • Racing or flight game physics

    The game simulates gravity, speed, and collisions using simplified equations so a car or plane behaves believably, while ignoring tiny real-world details to run in real time.

  • Crash-testing a car in software

    Engineers simulate a crash on a computer to see how a design holds up, letting them test dangerous scenarios safely and cheaply before building a real car.

Common Mistakes

  1. The slip: If a simulation runs and gives numbers, the numbers must be right.

    Why it's tempting: The computer produces precise output, which feels authoritative.

    Instead: A simulation is only as good as its model and assumptions; validate it against known real-world data before trusting its predictions.

  2. The slip: Adding more variables always makes a simulation more accurate.

    Why it's tempting: More detail sounds like it must mean more realism.

    Instead: Good simulations model the variables that matter and ignore the rest; extra variables can add complexity and slowness without improving accuracy.

  3. The slip: Small errors in the starting assumptions stay small.

    Why it's tempting: A tiny rounding or estimate seems too small to matter.

    Instead: Errors can compound step after step, so a small mistake early can produce wildly wrong long-term predictions (a key reason long forecasts are unreliable).


Mini Practice

Try these on your own. Tap Reveal when you want to check.

  1. A lunch-line simulation uses St+1=St+4−3: each minute 4 students join and 3 are served. The line starts with 2 students. How long is it after 10 minutes?

    Hint: Work out the net change per minute first.

  2. A rabbit simulation starts with 20 rabbits. Each step, the number grows by 50%, rounded down to a whole rabbit. How many rabbits are there after 3 steps?

    Hint: Apply the rule once per step: new = old + half of old.

  3. A cup of tea at 90 °C sits in a 20 °C room. Each minute the simulation lowers its temperature by 10% of the difference from room temperature. What is the temperature after 2 minutes?

    Hint: Minute 1: the difference is 70 °C. Recompute the difference before minute 2.

  4. A population model assumes 10% growth a year, but the true rate is 8%. Starting from 1,000, how far apart are the model and reality after 2 years?

    Hint: Multiply by 1.10 twice for the model and by 1.08 twice for reality.

  5. Program A lists the steps to make a sandwich. Program B lets you change how many cars arrive per minute at a crossing and shows how the queue changes over an hour. Which is a simulation?

    Hint: Which program imitates a real system changing over time so you can test 'what if'?

  6. A team's model says a ball dropped from 20 m lands in 4 s. A stopwatch test shows about 2.0 s. The team says: 'The computer calculated it, so it must be right. Let's predict a 50 m drop next.' What should they do instead?

    Hint: What does a big gap between model and measurement tell you?

Want the full set?

50 practice questions for this concept — free to try, every one with a complete worked solution showing the why, not just the answer.

Frequently Asked Questions

Why does running the same simulation twice sometimes give different answers?

If the simulation uses random numbers for chance events, each run takes a different path, just as two real flu seasons differ. That is why scientists run a simulation hundreds or thousands of times and look at the spread of results, such as 'the peak came between day 12 and day 18 in 90 out of 100 runs'. If you fix the random seed, a run repeats exactly, which helps when you are hunting for a bug.

How small should each time step be?

Small enough that nothing important happens between steps. If a ball moves 5 meters per step but a wall is only 1 meter thick, the program can jump the ball straight through the wall, a known glitch in games. Smaller steps are more accurate but mean more steps, so the run takes longer. Weather models strike this balance with steps of a few minutes of simulated time.

Can a simulation tell you about something that has never happened?

Yes, and that is much of its value. Before the Perseverance rover landed on Mars in 2021, engineers ran its landing thousands of times in simulation, because no practice landing on Mars was possible. The limit is that a simulation only knows the rules you gave it: a situation outside them, such as a dust storm stronger than any ever measured, can produce confident numbers that are wrong.

Learning Path

Simulation

You are here

You need Algorithm (steps a computer repeats) and Abstraction (keeping only the details that matter) first. Simulation combines them: a state, an update rule and repeated steps that imitate a real system so you can test changes safely. Next, Random Numbers add chance, such as whether each person catches a cold, and Modeling looks at how to build and check the rules themselves.

See Also