A learning resource fromSpread Robotics Education Foundation

Lesson 08 · 55 minutes · Random numbers

Build a digital dice

Shake the micro:bit and let the program choose a number from 1 to 6.

New programming concept

Randomisation

A random number is chosen without a predictable pattern. The pick random 1 to 6 block gives every roll one number in that range.

123456

Important: One roll cannot prove that a dice is fair. Test many rolls and make a tally.

Try it here

Roll several times

AB

Result: 1

Do you get every number? Do some repeat?

MakeCode steps

Build the dice

  1. 1

    Start a new project

    Name it Digital Dice.

    Open MakeCode
  2. 2

    Add the shake event

    From Input, add on shake.

  3. 3

    Add show number

    Place show number inside on shake.

  4. 4

    Replace zero

    From Math, put pick random 0 to 10 into show number.

  5. 5

    Set the dice range

    Change the first number to 1 and the second to 6.

    on shake
    show number pick random 1 to 6
  6. 6

    Test many rolls

    Roll at least 12 times and keep a tally. Compare with another team.

Optional videos

Watch the official guides

Visit the official Dice project

For the teacher

A calm 55-minute plan

Real dice warm-up
Predict, roll, and discuss uncertainty.

Introduce random
Name the range 1 through 6.

Guided build
Reuse the familiar shake event.

Tally test
Collect at least 12 results.

Compare
Discuss repeats and fairness cautiously.

Before you finish

Can you explain it?