LightMySky

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.

No account needed. Progress saves in this browser.

What a learner can do afterwards

  • 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

1 · Read

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.

Try it together

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.

Good to know

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.

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

2 · Watch

Take it off screen

Print a worksheetA4 with an answer key page for grown-ups. No screen, no internet.

Where it sits

Where this leads

Jobs that lean on this skill. Follow one to see everything it is built on.

Then practise

8 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.

Spotted a problem on this page? Tell us
Random Numbers and Programs That Differ Each Run · Computing, ages 12 to 13 · LightMySky