Chapter 8: Random Numbers & Variety
Make games replayable and lively using "pick random" for spawn positions, dice rolls, and enemy timing.
Lesson goal & core concept
Control randomness cleanly and store random choices in variables when needed in multiple checks.
Every time a "pick random" block runs, it generates a fresh number. If you want to test the same random roll in three "if" blocks, save it to a variable first!
Step-by-step practice
Work through these steps in the Scratch editor, predicting each result before clicking the green flag.
- Roll a 1–6 die into a variable named "roll".
- Spawn falling stars at x = pick random (-210) to (210).
- Add varied wait times: wait (pick random (0.5) to (1.5)) seconds.
- Verify that both endpoints (min and max) can appear.
- When green flag clicked
- Set roll to (pick random 1 to 6)
- Say (join You rolled: roll) for 2 seconds
Try it: Picks a single fair roll and displays it cleanly.
Mini challenge & next steps
Make a coin-flip simulator (1 = Heads, 2 = Tails) that counts how many Heads appear in 20 flips.
FAQ
How long should I spend on "Chapter 8: Random Numbers & Variety"?
Aim for 15–20 minutes: read the concept, test the small example, modify one value to see what changes, and try the mini challenge.
This guide is provided for educational purposes. Scratch screens and terms may change over time, so please check the official Scratch website as well.