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 times when you do want your program to do something surprising, for example:
To create random events we need to generate a random number.
We use a purple maths block to pick the random number.
The code below mimics a die (a single dice).
A variable has been created called die. When the micro:bit is shaken, the computer picks a random number between 1 and 6. This number is then assigned (put into) the variable 'die'.
The next block shows the number in the variable 'die' on the LEDs.
Shake the micro:bit to roll the die
Watch the video below to see how to make random number and assign it to a variable.
Create a program that:
Create a program that:
Without order. Numbers are picked within a range as if by chance.
Putting a piece of data into a variable