انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Block: home
0. Lab tour1
1. Getting started5
2. Motion5
3. Looks and sound5
4. Events4
5. Loops5
6. Conditions and sensing4
7. Variables and randomness4
8. Project: the “Catch Robo” game3
9. Messages: characters talk to each other4
10. Clones: one character, many copies4
11. My Blocks: make a new block3
12. Operators and time4
13. The pro project: a jumping game4

Random numbers

Section 7: Variables and randomnessLesson 7.2 · ⏱ 6 min

Random means a number you can't guess. Games need it so they don't play the same way every time.

Blocks: when 🚩 clicked, forever
🖥️ What happens on the stage?
Robo jumps to a new random place every second.
💡 Tip
The block pick random (1) to (10) gives you a random number. Put it inside wait to make the waiting random too.

📌 Another example: moody Robo

pick random chooses a different number every time: a random size from 50 to 150, and a random place.

Blocks: when 🚩 clicked, repeat (5)
Once
Once
And again
And again
✍️ Practise
Make Robo turn a random angle (from 0 to 360) every time you press space.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

Make Robo say a random number from 1 to 10.

👀 Show the solution
Blocks: when 🚩 clicked, say (pick random 1 to 10) for (2) seconds
The result on the stage
The result on the stage
Medium

Make Robo glide 3 times to a random x (from -200 to 200), with y staying 0.

👀 Show the solution
Blocks: when 🚩 clicked, go to x: (0) y: (0), repeat (3)
The result on the stage
The result on the stage
Hard

Roll a dice into a variable d: if it is 6 he says “I won! 🎉”, else he says “I rolled” and the number.

👀 Show the solution
Blocks: when 🚩 clicked, set (d) to (pick random 1 to 6), if <(d = 6)> then
The roll
The roll
Finished the lesson? Mark it so your progress counts.