📁 Paper 1 · 3.2 Programming
3.2.8 Random Number Generation
AQA 8525 · GCSE Computer Science · ~8 min read
Notes
──
Video
──
Worksheet
──
Quiz

What is Random Number Generation?

Programs can generate random numbers — numbers that cannot be predicted in advance. This is essential for games, simulations, testing, and security applications.

Computers use pseudo-random number generators (PRNGs) — algorithms that produce sequences of numbers that appear random but are actually deterministic (determined by a starting value called the seed).

AQA Pseudo-code — RANDOM()

In AQA pseudo-code, the function to generate a random integer is:

RANDOM(low, high) // Returns a random integer between low and high INCLUSIVE dice ← RANDOM(1, 6) // Simulates a dice roll (1 to 6) coinFlip ← RANDOM(0, 1) // 0 = Heads, 1 = Tails card ← RANDOM(1, 52) // Random card from a 52-card deck percentChance ← RANDOM(1, 100) // Random percentage

Using RANDOM() in Programs

Dice game example

score ← 0 FOR i ← 1 TO 5 // Roll dice 5 times roll ← RANDOM(1, 6) score ← score + roll OUTPUT "Roll " + str(i) + ": " + str(roll) ENDFOR OUTPUT "Total score: " + str(score)

Guessing game

secret ← RANDOM(1, 10) REPEAT guess ← int(INPUT("Guess 1–10: ")) IF guess < secret THEN OUTPUT "Too low" ELSEIF guess > secret THEN OUTPUT "Too high" ENDIF UNTIL guess == secret OUTPUT "Correct!"

Use Cases for Random Numbers

ApplicationHow RANDOM() is used
Dice / card gamesRANDOM(1,6) for a dice; RANDOM(1,52) for a card
SimulationsModelling probability, traffic flow, weather
Test data generationCreating random inputs to test programs
ShufflingRandomly reordering array elements
Password generationSelecting random characters from a character set
CryptographyGenerating random keys (requires true randomness)

Pseudo-random vs True Random

Pseudo-random numbers (PRNGs) use a mathematical algorithm. They are predictable if you know the seed — the same seed always produces the same sequence.

True random numbers are unpredictable — generated from physical processes (mouse movements, radioactive decay). These are required for cryptography.

Pseudo-randomTrue random
SourceAlgorithm + seedPhysical process
Predictable?Yes (with same seed)No
SpeedFastSlower
Use caseGames, simulationsEncryption keys
Exam tip: RANDOM(low, high) in AQA is INCLUSIVE at both ends — RANDOM(1,6) can return 1, 2, 3, 4, 5, or 6. This is different from some languages where the upper bound is exclusive.
⚠️ Common Mistakes
  • Thinking RANDOM is truly random — it is pseudo-random (algorithm-based)
  • Writing RANDOM(6) instead of RANDOM(1,6) — must specify BOTH bounds
  • Off-by-one with bounds — RANDOM(0,9) gives 0 to 9, not 1 to 9
Video coming soon

Key points

  • RANDOM(low, high) returns a random integer inclusive of both bounds
  • Computers use pseudo-random algorithms (PRNGs)
  • Uses: dice games, simulations, test data, passwords
  • True randomness requires a physical process — needed for cryptography
Click slide or press arrow keys to navigate
✍️

Worksheet — 3.2.8 Random Numbers

8 questions · 20 marks

Q1Write the AQA pseudo-code to simulate rolling a standard six-sided die and store the result in a variable called 'roll'.[2]
✅ Mark scheme
Mark scheme
roll ← RANDOM(1, 6) [2] — must have both bounds (1 and 6), correct syntax for 1 mark if minor error.
Q2What range of values can RANDOM(10, 20) return? Is the result inclusive of the bounds?[2]
✅ Mark scheme
Mark scheme
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 — any integer between 10 and 20 [1]; yes, both 10 and 20 are included (inclusive) [1].
Q3Write pseudo-code to simulate a coin flip: randomly output either "Heads" or "Tails".[3]
✅ Mark scheme
Mark scheme
flip ← RANDOM(0, 1) [1]; IF flip == 0 THEN OUTPUT "Heads" [1]; ELSE OUTPUT "Tails" ENDIF [1].
Q4Explain the difference between pseudo-random and true random number generation.[2]
✅ Mark scheme
Mark scheme
Pseudo-random numbers are produced by an algorithm / are deterministic — predictable with the same seed [1]; true random numbers come from unpredictable physical processes and cannot be reproduced [1].
Q5Write pseudo-code to roll two dice 10 times and output the sum each time. Count how many times the sum is 7.[4]
✅ Mark scheme
Mark scheme
count ← 0 [1]; FOR i ← 1 TO 10 [1]; d1 ← RANDOM(1,6); d2 ← RANDOM(1,6); sum ← d1 + d2; OUTPUT sum [1]; IF sum == 7 THEN count ← count + 1 ENDIF [1]; ENDFOR.
Q6Give TWO applications where generating random numbers is useful in software.[2]
✅ Mark scheme
Mark scheme
Any two from: game simulations (dice, cards, NPC behaviour) [1]; generating test data [1]; creating random passwords or tokens [1]; cryptographic key generation [1]; traffic/weather simulations [1] — max 2.
Q7Why are pseudo-random number generators NOT suitable for generating encryption keys?[2]
✅ Mark scheme
Mark scheme
PRNGs are predictable — if an attacker knows the seed/algorithm, they can reproduce the sequence [1]; encryption keys must be truly unpredictable to be secure [1].
Q8Write pseudo-code to generate 5 random numbers between 1 and 100 and output both the number and whether it is even or odd.[3]
✅ Mark scheme
Mark scheme
FOR i ← 1 TO 5 [1]; num ← RANDOM(1, 100) [1]; IF num MOD 2 == 0 THEN OUTPUT str(num) & " Even" ELSE OUTPUT str(num) & " Odd" ENDIF [1]; ENDFOR.
Check your answers above.
Topic Quiz
Q 1 of 10
You scored
out of 10
Card 1 of 5
Click to flip
🎉
All done!
TermDefinition
🎯

Mini Test — 3.2.8 Random Numbers

Timed exam conditions.

  • 8 questions · 10 minutes
  • 5 MCQ + 3 short answer
← 3.2.7/9 File Handling
19 of 57 · AQA 8525
3.2.10a Subroutines →