---
title: "Simulation — AP Comp Sci A Definition & FRQ Guide"
description: "A simulation is code that models a real-world process using loops, conditionals, and state changes. It anchors FRQ 1 on AP CS A, like 2024's bird feeder."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/simulation"
type: "key-term"
subject: "AP Computer Science A"
unit: "Unit 2"
---

# Simulation — AP Comp Sci A Definition & FRQ Guide

## Definition

In AP Computer Science A, a simulation is a program that models a real-world process by repeatedly updating variables (state) with loops and making decisions with conditionals, sometimes using random values, like the 2024 FRQ that simulated birds and a bear eating from a feeder.

## What It Is

A simulation is code that pretends to be something in the real world. Instead of actually watching birds eat from a feeder for ten days, you write a [loop](/ap-comp-sci-a/key-terms/loop "fv-autolink") that runs ten times, and inside that loop you [update](/ap-comp-sci-a/unit-2/for-loops/study-guide/DJuLxKz6SiSAX2cEVmCt "fv-autolink") a variable that tracks how much food is left. The variable is the **state** of the simulation, and each pass through the loop is one step of time (a day, a hop, a level of a game).

Every simulation on the AP exam is built from the three algorithm building blocks in EK 2.1.A.1: [sequencing](/ap-comp-sci-a/unit-1/why-programming-why-java/study-guide/lVK6rmrBuug17i1Hna9z "fv-autolink"), selection, and repetition. Repetition (a `for` or `while` loop) moves the simulation forward step by step. Selection (an `if` statement) decides what happens at each step, like whether a bear shows up or whether the frog reached its goal. Sequencing makes sure those updates happen in the right order, which matters because EK 2.1.A.5 says the order of these pieces changes the outcome. Many simulations also use `Math.random()` to model unpredictable events, but randomness is optional. A traffic light cycling on a fixed timer is still a simulation.

## Why It Matters

Simulation lives in [Unit 2](/ap-comp-sci-a/unit-2 "fv-autolink") (Selection and Iteration), Topic 2.1, and directly supports learning objective [AP Comp Sci A](/ap-comp-sci-a "fv-autolink") 2.1.A, which asks you to represent real-life patterns and algorithms that involve selection and repetition. Simulation is where that objective stops being abstract. "Repetition is when a process repeats itself until a desired outcome is reached" (EK 2.1.A.4) is literally what a frog-hopping simulation does, hopping until it reaches the goal or runs out of hops. On the exam side, simulation is arguably the highest-stakes word in the course. FRQ Question 1 (Methods and Control Structures) is a simulation question year after year, so being comfortable with the loop-update-decide pattern is worth real points.

## Connections

### Selection (if statements) (Unit 2)

[Selection](/ap-comp-sci-a/unit-2/algorithms-with-selection-and-repetition/study-guide/42crNSZyW8IRsntk9IHe "fv-autolink") is how a simulation makes choices. In the 2024 bird feeder FRQ, an if statement decided whether a bear ate everything or birds ate a normal amount. Per EK 2.1.A.3, the program branches based on a true/false decision, often one driven by Math.random().

### Repetition (loops) (Unit 2)

Loops are the engine of every simulation. Each [iteration](/ap-comp-sci-a/unit-2/while-loops/study-guide/7qGsGOh1UKALAWpJhZOi "fv-autolink") represents one unit of time, like one day of feeding or one hop of the frog. A while loop is the natural fit when the simulation runs "until a desired outcome is reached" (EK 2.1.A.4), like the frog reaching its goal.

### Algorithm building blocks and ordering (Unit 2)

EK 2.1.A.5 warns that the order of sequencing, selection, and repetition changes the result. In a simulation this is painfully concrete. Checking whether food ran out before subtracting what was eaten gives a different answer than checking after, and FRQ graders notice.

## On the AP Exam

Simulation is the classic setup for FRQ Question 1. The 2018 exam simulated a frog hopping toward a goal, 2022 simulated playing and scoring a three-level video game, and 2024 simulated birds (or a hungry bear) eating from a feeder. In each one, you write methods that run a loop, use conditionals to handle different cases, and update state variables along the way. Multiple-choice questions test the same skill from the reading side. A typical stem gives you a short simulation, like a traffic light that increments a timer by 5 each loop iteration and resets after hitting 15, and asks what gets printed. Your job is to trace the loop carefully, tracking every variable on each iteration. The two skills to drill are writing the loop-decide-update pattern from a spec, and hand-tracing someone else's simulation without losing count.

## simulation vs Random number generation (Math.random())

Randomness shows up in lots of simulations, like the 2024 FRQ where a bear arrives with some probability, so it's easy to think simulation means random. It doesn't. A simulation is the overall model (state plus loops plus decisions), and Math.random() is just one optional ingredient for modeling unpredictable events. A traffic light simulation on a fixed timer has zero randomness and is still a simulation. Flip side, a single call to Math.random() with no loop or state isn't really a simulation, just a random value.

## Key Takeaways

- A simulation models a real-world process in code by repeatedly updating state variables inside a loop and using conditionals to decide what happens at each step.
- Simulations are built from the three algorithm building blocks in EK 2.1.A.1: sequencing, selection, and repetition.
- FRQ Question 1 on the AP CS A exam is consistently a simulation question, including the 2018 frog hopper, the 2022 video game, and the 2024 bird feeder.
- Randomness via Math.random() is common in simulations but not required; a fixed traffic light cycle is still a simulation.
- The order of operations inside the loop matters (EK 2.1.A.5), so checking a condition before versus after updating a variable can change the entire result.
- To trace a simulation in a multiple-choice question, track every variable's value through each loop iteration rather than guessing the pattern.

## FAQs

### What is a simulation in AP Computer Science A?

A simulation is a program that models a real-world process by running a loop where each iteration represents a step of time, updating [variables](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr "fv-autolink") that track state and using if statements to handle decisions. The 2024 FRQ's bird feeder, which tracked remaining food over several days of feeding, is a textbook example.

### Does a simulation always use Math.random()?

No. Randomness models unpredictable events, like a bear showing up at a feeder, but plenty of simulations are fully deterministic. A traffic light that increments a timer by 5 each loop pass and turns red at 15 is a simulation with no randomness at all.

### How is a simulation different from a regular algorithm?

Every simulation is an algorithm, but not every algorithm is a simulation. A simulation specifically mimics a real-world process over time, with loop iterations standing in for time steps and variables standing in for real-world quantities like food remaining or distance hopped.

### Is simulation actually on the AP CS A exam?

Yes, heavily. FRQ Question 1 has been a simulation in recent years, including a frog hopping toward a goal (2018), a single-player video game (2022), and a bird feeder (2024), and multiple-choice questions regularly ask you to trace simulation code.

### Should I use a for loop or a while loop in a simulation?

Use a for loop when the number of steps is fixed, like simulating exactly 10 days of feeding, and a while loop when the simulation runs until a condition is met, like a frog hopping until it reaches the goal or runs out of hops (EK 2.1.A.4).

## Related Study Guides

- [2.1 Algorithms with Selection and Repetition](/ap-comp-sci-a/unit-2/algorithms-with-selection-and-repetition/study-guide/42crNSZyW8IRsntk9IHe)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/simulation#resource","name":"Simulation — AP Comp Sci A Definition & FRQ Guide","url":"https://fiveable.me/ap-comp-sci-a/key-terms/simulation","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/simulation#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T05:27:19.453Z","isPartOf":{"@type":"Collection","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/simulation#term","name":"simulation","description":"In AP Computer Science A, a simulation is a program that models a real-world process by repeatedly updating variables (state) with loops and making decisions with conditionals, sometimes using random values, like the 2024 FRQ that simulated birds and a bear eating from a feeder.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/simulation","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is a simulation in AP Computer Science A?","acceptedAnswer":{"@type":"Answer","text":"A simulation is a program that models a real-world process by running a loop where each iteration represents a step of time, updating [variables](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr \"fv-autolink\") that track state and using if statements to handle decisions. The 2024 FRQ's bird feeder, which tracked remaining food over several days of feeding, is a textbook example."}},{"@type":"Question","name":"Does a simulation always use Math.random()?","acceptedAnswer":{"@type":"Answer","text":"No. Randomness models unpredictable events, like a bear showing up at a feeder, but plenty of simulations are fully deterministic. A traffic light that increments a timer by 5 each loop pass and turns red at 15 is a simulation with no randomness at all."}},{"@type":"Question","name":"How is a simulation different from a regular algorithm?","acceptedAnswer":{"@type":"Answer","text":"Every simulation is an algorithm, but not every algorithm is a simulation. A simulation specifically mimics a real-world process over time, with loop iterations standing in for time steps and variables standing in for real-world quantities like food remaining or distance hopped."}},{"@type":"Question","name":"Is simulation actually on the AP CS A exam?","acceptedAnswer":{"@type":"Answer","text":"Yes, heavily. FRQ Question 1 has been a simulation in recent years, including a frog hopping toward a goal (2018), a single-player video game (2022), and a bird feeder (2024), and multiple-choice questions regularly ask you to trace simulation code."}},{"@type":"Question","name":"Should I use a for loop or a while loop in a simulation?","acceptedAnswer":{"@type":"Answer","text":"Use a for loop when the number of steps is fixed, like simulating exactly 10 days of feeding, and a while loop when the simulation runs until a condition is met, like a frog hopping until it reaches the goal or runs out of hops (EK 2.1.A.4)."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science A","item":"https://fiveable.me/ap-comp-sci-a"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-a/key-terms"},{"@type":"ListItem","position":3,"name":"Unit 2","item":"https://fiveable.me/ap-comp-sci-a/unit-2"},{"@type":"ListItem","position":4,"name":"simulation"}]}]}
```
