Random Numbers
π¨π± Random Numbers in Scratch (practical)
π― What Are Random Numbers?
Scratch has a block that gives you a random number between and including two values. This is great for adding surprises, challenges, or variety to your projects.
Youβll find it in the Operators category (green):
It chooses a random whole number (integer) between the two numbers you set.
π§ͺ Try It!
Make a sprite go to a random spot:
Roll a dice:
Choose a random costume:
π Top Tips
-
You can use random numbers for:
-
Random movement of enemies or fish π
- Chance events in games (like coins falling or powerups appearing)
- Generating questions or puzzles
- Making computer decisions in AI-like games
-
Visual effects, like twinkling stars β¨ or popping bubbles
-
The numbers donβt have to be positive β you can go from -100 to 100 if you like.
β οΈ Watch Out!
- The numbers are whole numbers (integers), not decimals.
- The result includes both ends β so
pick random 1 to 6
could return 1 or 6.
π οΈ Challenges
- Make a sprite say a random number between 1 and 100.
- Use
pick random
in a repeat block to move randomly around the screen. - Create a "fortune teller" that gives a random message when clicked.
- Build a dice game using random numbers and variables.