Revise Computing
Revision notesQuestionsFor schools
Log inStart revising free
Revision notesQuestionsFor schoolsLog in
GCSE Computer Science/Supplementary programming practice/Random Number Generation

Games

301.14 Random Number Generation

Practise exam questions

Random Number Generation — Note 2 of 3

Use random in game logic.

What you need to know

Random numbers are essential in games for dice rolls, card shuffling, enemy spawning, and guessing games. Combine random.randint() with loops and selection for game logic.

What to know

  • Dice games: random.randint(1, 6)
  • Guessing games: pick a secret number, player guesses
  • Use loops for repeated rounds
  • Compare user input against the random number

Code examples

Number guessing game
python
import random
secret = random.randint(1, 100)
guess = 0
while guess != secret:
    guess = int(input("Guess (1-100): "))
    if guess < secret:
        print("Higher!")
    elif guess > secret:
        print("Lower!")
print("Correct!")
← Previous noteRandom integers301.14 Random Number GenerationNext note →Off-by-one301.14 Random Number Generation

Back to Random Number Generation

Specification notes for programming are in Paper 2.

Random Number Generation

Note 2 of 3

  1. 1Random integers
  2. 2Games
  3. 3Off-by-one
Topic overview

© 2026 Revise Computing · revisecomputing.co.uk

Privacy noticeTermsContact

Revise Computing is an independent revision resource. It is not affiliated with, or endorsed by, OCR (Oxford Cambridge and RSA Examinations).