Random whole numbers with ROUND and RANDOM
Gives a random whole number from 0 to 6. RANDOM() gives a decimal from 0 to 1, times 6 stretches it, and ROUND(..., 0) turns it into a whole number.
Understanding Random whole numbers with ROUND and RANDOM in IGCSE Computer Science Paper 2
What it does: RANDOM() runs first inside the brackets, then its result is multiplied by 10 and passed to ROUND(), which makes a whole number from 0 to 10. Adding 1 moves the whole range up. 0 to 6 becomes 1 to 7. Multiplying by 1 changes nothing. A function must RETURN its value to the code that called it. Times 5 gives 0 to 5, and + 1 makes it 1 to 6, like a die. Multiplying by the wrong number makes the top of the range too large, so the die could roll an impossible 7.
Common mistakes: ROUND needs a second argument saying how many decimal places to keep. For a whole number it must be ROUND(RANDOM() * 6, 0). A function must pass its result back to the caller with RETURN. OUTPUT only displays the value, so line 4 should be RETURN N.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 429–438) and word search (Modules 419–438).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
ROUND(RANDOM() * 6, 0)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →