DoRevision

Roll the Dice

How a program makes a random number, why it needs a low and a high bound, that the range is usually inclusive of both ends, and what random numbers are used for.

⏱️ 15 min 🎯 14 activities
Best used for
Starter Intervention Mock preparation

Get the method right under pressure

Free interactive practice on the steps that lose marks under exam pressure.

Start revising free

What you'll cover

Making a program roll a dice

A game would be dull if it did the same thing every time. Programs use random numbers to add surprise: a dice roll, a shuffled deck, or a randomly chosen question. A random number is not picked out of thin air, though, it is chosen from a range you set. This module shows how random numbers are made and used.

Random words to know

Learn these before you set a range.

Fixed against random

A value can be set once, or chosen fresh each time.

Give a low and a high

To make a random number you give the function two bounds, the smallest and the largest value it may return, and it picks a whole number in that span. Usually both ends of the span can be chosen. Match the span to the job: a dice needs the numbers one to six, while a coin needs only two. Set the bounds and the program does the rest.

Match the term

  • random number
  • range
  • inclusive
  • simulation
  • an unpredictable value
  • the low and high bounds
  • both ends can be chosen
  • imitating something real

Match the use to the range

  • rolling one dice
  • flipping a coin
  • picking a card position
  • a random score out of 100
  • a random number from 1 to 6
  • a random number from 1 to 2
  • a random number from 1 to 52
  • a random number from 0 to 100

What does the function need?

What must you give a random number function so it knows what to return?

  • A low bound and a high bound for the range.
  • Nothing at all; it just guesses.
  • A colour for the number.
  • A name for the dice.

Good uses of random numbers

Select the TWO good uses of random numbers in a program.

  • Rolling a dice in a game
  • Simulating the toss of a coin
  • Storing a fixed customer name
  • Adding up a shopping bill

Count the dice values

A program asks for a random whole number from 1 to 6, including both 1 and 6. How many different values can it give?

Order the dice roll

Put the steps of making a program roll a dice in order, earliest first.

  • Decide the range, 1 to 6
  • Call the random function
  • Store the number it returns
  • Use it as the dice roll

Complete the rules

A random number is chosen from a _____ that you set with a low and a high bound. In most exam languages the range is _____, so both ends can come up. Random numbers make a program _____, which is useful for games and _____.

range inclusive unpredictable simulations record exclusive slower spreadsheets

Spot the random jobs

Tap the TWO tasks that a random number is right for.

  • choosing a dice roll
  • shuffling a deck of cards
  • adding up a shopping bill
  • storing a fixed username

Choose the range

Read each task and choose the correct range.

  • You want a random result for a single six-sided dice. What range should you ask for?
  • You want to simulate a coin that lands heads or tails. What range works?
  • A program always needs the same fixed tax rate. Should it use a random number?

Explain random numbers

Explain how a program makes a random number within a range, and give two good uses of random numbers.

  • Say what a low and a high bound are for
  • Explain what inclusive means for the range
  • Give two uses of random numbers in programs