Using our website means you agree to using cookies which help us improve microbit.org.Learn more
Skip to content

Activity

Dice

Beginner | MakeCode, Python | Accelerometer, LED display | Input/output, Randomisation, Sensors

Step 1: Make it

What is it?

Shake your micro:bit to make random numbers

real die next to micro:bit being shaken showing number 6 on its LED display

How it works

  1. Like the Get silly project this program uses the micro:bit’s accelerometer to make something happen when you shake it.
  2. When you shake your micro:bit, the program selects a random number between 1 and 6 and shows it on the LED display.
  3. It's really hard for computers to make truly random numbers because they’re machines that work precisely and regularly.
  4. Make a tally chart of how often each number comes up. Are these numbers really random? Compare it with real dice.

What you need

  • micro:bit (or MakeCode simulator)
  • MakeCode or Python editor
  • battery pack (optional)
  • real dice (optional)

Step 2: Code it

Step 3: Improve it

  • Make the number appear for a few seconds, then clear the LED display to save batteries.
  • Make it roll 2 dice. You can make a random number between 2 and 12, or you can make two random numbers between 1 and 6 and add them together.
  • Try both methods and tally how often each score occurs. Does it make a difference? Do some numbers come up more often than others?