Oxford Cambridge and RSA
GCSE (9-1) Computer Science
Algorithms & Programming
J277/02
Topic: Random Number Generation
Time allowed: 45 minutes
Centre number Candidate number
First name Last name
INSTRUCTIONS INFORMATION
Turn over
Section A: Core Concepts & Syntax
1
A program is written to simulate rolling a standard 6-sided die. Fill in the missing keywords to assign a random number between 1 and 6 to the variable roll.
import ......................... roll = random.randint(........., .........) print(roll)
[3]
2
State two types of software applications where Random Number Generation is essential.
[2]
3
Consider the following line of code in OCR Exam Reference Language:
myNum = random(1, 5)

(a) What is the lowest possible value myNum can hold?
[1]

(b) What is the highest possible value myNum can hold?
[1]
Section B: Debugging & Logic
4
A student writes a program to simulate a "Magic 8 Ball" that gives one of three answers: "Yes", "No", or "Maybe". There is a Logic Error that means sometimes nothing is output.
01 import random 02 print("Ask a question...") 03 04 if random.randint(1, 3) == 1: 05 print("Yes") 06 elif random.randint(1, 3) == 2: 07 print("No") 08 elif random.randint(1, 3) == 3: 09 print("Maybe") 10 endif
(a) Explain why this code might sometimes output nothing at all.
[2]

(b) Rewrite the code (using Pseudocode or Python) so that it works correctly and guarantees exactly one output every time.
[3]
Turn over
Section C: Coding & Application
5
Write a program to simulate a "Coin Toss". The program must:
  • Generate a random number.
  • If the number represents "Heads", output "Heads".
  • If the number represents "Tails", output "Tails".
[4]
6
You have a list of students: students = ["Ali", "Bea", "Caz", "Dan", "Eve"].
Write an algorithm that picks one student at random to answer a question and prints their name.

Constraint: Your code must work correctly even if more names are added to the list later (i.e., do not hard-code the number 4).
[6]
END OF QUESTION PAPER