SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
AQA 8525 · Section 3.2 · 3.2.8
Random
Numbers
RANDOM(x, y) · Simulations · Games & Modelling
CSZone
AQA GCSE Computer Science 8525
The RANDOM Function
Generating Random Numbers in AQA
RANDOM(x, y)
— returns a random integer between x and y
inclusive
.
Both x and y are included in the possible results.
dice ← RANDOM(1, 6)
OUTPUT dice
← Could be 1, 2, 3, 4, 5 or 6
coin ← RANDOM(0, 1)
← 0 = Heads, 1 = Tails
Key:
RANDOM(1, 6) can return 1, 2, 3, 4, 5 or 6 — all six values are possible.
Using RANDOM in Programs
Practical Examples
DICE GAME
FOR i ← 1 TO 10
roll ← RANDOM(1,6)
OUTPUT 'You rolled: ' + STR(roll)
ENDFOR
RANDOM QUIZ QUESTION
qNum ← RANDOM(1, 20)
OUTPUT 'Question ' + STR(qNum)
x ← RANDOM(2,12)
y ← RANDOM(2,12)
OUTPUT STR(x) + ' × ' + STR(y) + ' = ?'
Why Use Random Numbers?
Real-World Uses
Games
— dice rolls, card shuffles, enemy AI behaviour, spawn locations
Simulations
— weather modelling, traffic flow, population studies
Security
— generating passwords, salts, session tokens
Education
— random quiz questions, shuffled tests
Note:
Computers generate
pseudo-random
numbers using a mathematical algorithm — they're not truly random.
Exam Practice
Have a go at this question
AQA-style question
Write pseudocode to simulate rolling two dice 5 times and output the total of both dice each time.
4 marks
FOR i ← 1 TO 5
dice1 ← RANDOM(1, 6)
dice2 ← RANDOM(1, 6)
total ← dice1 + dice2
OUTPUT 'Total: ' + STR(total)
ENDFOR
Key Takeaways
What to Remember
RANDOM(x, y)
— returns a random integer from x to y inclusive
RANDOM(1, 6) simulates a
dice roll
— all 6 values equally possible
Used in
games, simulations, security
and testing
Computers produce
pseudo-random
numbers — deterministic algorithms