Revise Computing
Revision notesQuestionsFor schools
Log inStart revising free
Revision notesQuestionsFor schoolsLog in
GCSE Computer Science/Paper 2/Additional Programming Techniques

Random number generation

2.2.3 Additional Programming Techniques

Practise exam questions

Additional Programming Techniques — Note 12 of 12

Be able to create and use random numbers in a program

What you need to know

Random number generation allows programs to produce unpredictable values within a specified range. This is useful for games (dice rolls, card draws), simulations, testing, and security. In OCR pseudocode the syntax is random(min, max); in Python you use the random module.

What to know

  • random(min, max) generates a random integer between min and max inclusive (OCR pseudocode).
  • In Python: import random, then random.randint(min, max) for integers.
  • random.randint() is inclusive of both endpoints.
  • Store the random value in a variable if it will be used more than once.
  • Useful for: dice rolls, random questions, game outcomes, test data generation.
  • Can generate both integer and real (float) random numbers.

Code examples

Random number generation
python
import random

# Random integer between 1 and 6 (dice roll)
dice = random.randint(1, 6)
print("You rolled:", dice)

# Random float between 0.0 and 1.0
chance = random.random()
print("Random chance:", chance)

# Random choice from a list
colours = ["red", "blue", "green"]
pick = random.choice(colours)
print("Chosen colour:", pick)

Ready to test yourself?

Practise 2.2.3 questions
← Previous notearrays2.2.3 Additional Programming TechniquesNext topic →Anticipating misuse, Authentication2.3.1 Defensive Design

Back to Additional Programming Techniques

Revise another OCR GCSE topic: Programming Fundamentals

Additional Programming Techniques

Note 12 of 12

  1. 1Concatenation
  2. 2slicing
  3. 3Open, Read, Write, Close
  4. 4Records to store data
  5. 5SQL to search for data
  6. 6one-dimensional (1D)
  7. 7two-dimensional arrays(2D)
  8. 8Sub programs (functions and procedures) to produce structured code
  9. 9local variables
  10. 10global variables
  11. 11arrays
  12. 12Random number generation
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).