---
title: "Random Numbers and Programs That Differ Each Run"
description: "A random value makes a program behave differently every time it runs. That is what games and simulations need, and it changes what counts as having tested the program."
canonical: https://lightmysky.com/learn/computing/random-numbers-and-programs-that-differ-each-run-mt_t8GTOW3hyN
source: https://lightmysky.com/learn/computing/random-numbers-and-programs-that-differ-each-run-mt_t8GTOW3hyN.md
retrieved: 2026-09-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Random Numbers and Programs That Differ Each Run

A random value makes a program behave differently every time it runs. That is what games and simulations need, and it changes what counts as having tested the program.

Subject: Computing · Area: Computing Fundamentals · Ages 12 to 13
Page: https://lightmysky.com/learn/computing/random-numbers-and-programs-that-differ-each-run-mt_t8GTOW3hyN

## Ready when they can

- Use a random number in a chosen range so that nothing lands outside the screen or the allowed values
- Run the same program three times and say what stayed the same and what changed
- Explain why 'it worked when I ran it' is weaker evidence once a random value is involved

## Lesson: A new surprise every run

A random value makes a program behave differently every time it runs. Games and simulations need that surprise. You pick the range, and the computer picks a value inside it.

**Example.** Picture a dice game that rolls a number from 1 to 6. One run shows 4, the next shows 1, because each run picks fresh. If a number below 3 shows Trick and the rest show Treat, either word can appear on any run.

Keep every value inside its allowed range. A game piece that can land off the screen will vanish one day. Test the edges of your range, not just the middle.

**Tip.** One good run proves little. Flip a coin ten times and you might see ten heads in a row. Run the program many times, write down what stayed the same and what changed, and judge it on the whole set.

**Recap.** Random values change each run within your range, so test many runs and compare what held steady.

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Conditions That Combine: And, Or and Not](https://lightmysky.com/learn/computing/conditions-that-combine-and-or-and-not-mt_ZYdtXQZy5r)

## Opens up

- [Finding a Bug by Changing One Thing at a Time](https://lightmysky.com/learn/computing/finding-a-bug-by-changing-one-thing-at-a-time-mt_DMgajrUSy_)
