Computers follow instructions and will only do what you tell them to do. They will do the same thing every time you ‘run’ the program. This is a good thing.
However, there are time when you do want your program to do something surprising, for example:
To create random events we need to generate a random number.
In scratch we use the ‘pick random’ operator.
This operation will choose a random number between the two numbers that we can then use in our programming.
In the example below the program picks a random number between 1 and 2 (inclusive), and assigns it to a variable called ‘number’.
IF the number is 1 it shows the ‘heads’ otherwise (ELSE) it shows tails.
Click the coin to see the program in action
Watch the video below to see how to use the PICK RANDOM operator block to flip a coin and roll a die.
You can download the files for the challenges at the bottom of this page.
Create a program that generates 2 random numbers (between 1 and 100) and stores them in 2 seperate variables.
The Maths Man should then add the two numbers together and say the answer.
Create a program that asks the user to pick a prize box between 1 and 6.
The computer should also pick a random box between 1 and 6.
You will need to store their answer in a variable.
IF they pick the right box they win £1000 otherwise (ELSE) they win a cabbage.
The Quizmaster sprite has 3 costumes:
Create a program that generates 2 random numbers (between 1 and 100) and stores them in 2 seperate variables.
The quizmaster should ask the player to add the numbers together.
You will need to store their answer in a variable.
The program should tell the user IF their answer was right or wrong.
Create a program that will draw random regular polygons (a minimum of 3 sides to a maximum of 18).
The random operator generates a random number between two values.