Random Number Generation (AQA GCSE Computer Science): Revision Note

Exam code: 8525

James Woodhouse

Written by: James Woodhouse

Reviewed by: Lucy Kirkham

Updated on

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)

import random

number = random.randint(1,10)

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: ") # asking 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 5 free revision notes this week

Unlock more, it's free!

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

the (exam) results speak for themselves:

James Woodhouse

Author: James Woodhouse

Expertise: Computer Science & English Subject Lead

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.

Lucy Kirkham

Reviewer: Lucy Kirkham

Expertise: Head of STEM

Lucy has been a passionate Maths teacher for over 12 years, teaching maths across the UK and abroad helping to engage, interest and develop confidence in the subject at all levels.Working as a Head of Department and then Director of Maths, Lucy has advised schools and academy trusts in both Scotland and the East Midlands, where her role was to support and coach teachers to improve Maths teaching for all.