Random Number Generation (AQA GCSE Computer Science)

Revision Note

James Woodhouse

Expertise

Computer Science

Random Number Generation

What is random number generation?

  • Random number generation is a programming concept that involves a computer generating a random number to be used within a program to add an element of unpredictability
  • Examples of where this concept could be used include:
    • Simulating the roll of a dice
    • Selecting a random question (from a numbered list)
    • National lottery
    • Cryptography 
Concept Pseudocode Python
Random numbers

number ← RANDOM_INT(1,10)

number ← RANDOM_INT(-1.0,10.0)

import random

number = random.randint(1,10)

number = random.randint(-1.0,10.0)

Examples in Python

Random code

import random # importing random module

user = input("Enter a username: ") # asking user to enter a username
pw = input("Enter a password: ") # aksing user to enter a password

if user == "admin" and pw == "1234": # checking if the user and password are correct
  code = random.randint(1000,9999) # generating a random 4 digit code
  print("Your code is", code) # printing the code

National lottery

import random # importing random module

num1 = random.randint(1,59) # generating a random number between 1 and 59
num2 = random.randint(1,59)
num3 = random.randint(1,59)
num4 = random.randint(1,59)
num5 = random.randint(1,59)
num6 = random.randint(1,59)

print("Your lucky dip numbers are: ", num1, num2, num3, num4, num5, num6) # printing the numbers

You've read 0 of your 0 free revision notes

Get unlimited access

to absolutely everything:

  • Downloadable PDFs
  • Unlimited Revision Notes
  • Topic Questions
  • Past Papers
  • Model Answers
  • Videos (Maths and Science)

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

James Woodhouse

Author: James Woodhouse

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.