New
New
Year 10
AQA

Randomisation

I can import the random module into my code to produce random numbers.

New
New
Year 10
AQA

Randomisation

I can import the random module into my code to produce random numbers.

These resources will be removed by end of Summer Term 2025.

Switch to our new teaching resources now - designed by teachers and leading subject experts, and tested in classrooms.

These resources were created for remote use during the pandemic and are not designed for classroom teaching.

Lesson details

Key learning points

  1. Be able to locate information using the language documentation.
  2. Import modules into your code.
  3. Demonstrate how to generate random numbers.

Keywords

  • Module - a file with pre-made code you can use in your own programs

  • Standard library - a collection of built-in modules that come with Python

Common misconception

You have to write the full code for random number generation yourself.

Python's standard library includes the random module, which already has functions like randint() to generate random numbers. You just need to import it.


To help you plan your year 10 computer science lesson on: Randomisation, download all teaching resources for free and adapt to suit your pupils' needs...

Demonstrate how to access Python’s online documentation to explore the available functions in a module like random. Pupils should be encouraged to research code functionality for themselves to support their learning.
Teacher tip

Equipment

Code in this lesson is made using Python. Code examples use the RPF Code Editor but any Python IDE is suitable.

Licence

This content is © Oak National Academy Limited (2025), licensed on Open Government Licence version 3.0 except where otherwise stated. See Oak's terms & conditions (Collection 2).

Lesson video

Loading...

6 Questions

Q1.
What is a nested loop?
Correct answer: a loop inside another loop
a loop that runs indefinitely
a loop that only runs once
a loop that processes random numbers
Q2.
What does the outer loop in a nested loop do?
processes random numbers
Correct answer: controls how many times the inner loop repeats
stops the inner loop from running
generates output for the inner loop
Q3.
How does the inner loop behave in a nested loop?
it runs once and stops
it runs independently of the outer loop
it only processes random numbers
Correct answer: it runs completely for each outer loop iteration
Q4.
What is the main advantage of using nested loops?
they simplify random number generation
Correct answer: they allow repetitive tasks within repetitive tasks
they make the program run faster
they prevent errors in the code
Q5.
How do you ensure a nested loop works correctly?
Correct answer: use proper indentation
import the random module
avoid using an inner loop
only use one iteration
Q6.
How many times will this print a line?
123
for day in range(3): for hour in range(2): print("Time slot")
Code colour

When programmers write code, they use a special tool called an IDE (Integrated Development Environment). In an IDE, different colours are used to help programmers understand the code:


  • • Blue - numbers and boolean values
  • • Green - strings
  • • Purple - keywords
Correct answer: 6
1
3
5

6 Questions

Q1.
Do you need to write all the code for random number generation yourself?
Yes, Python doesn’t have built-in functions.
Yes, it’s required for every program.
Correct answer: No, Python’s standard library includes the random module.
No, but you have to create your own module.
Q2.
What is a module in Python?
a collection of built-in functions
Correct answer: a file with pre-made code you can use in your programs
a programming loop
a tool for drawing shapes
Q3.
What is the standard library in Python?
a place to store user data
a tool to create loops automatically
a generator for random numbers
Correct answer: a collection of built-in modules that come with Python
Q4.
How do you import a module in Python?
use module()
include module_name
Correct answer: `import module_name`
add module_name()
Q5.
How do you generate a random whole number between 1 and 10?
Correct Answer: randint(1,10)
Q6.
Match the term to its function:
Correct Answer:`random.choice`,selects a random item from a list or string
random.choice
- 

selects a random item from a list or string

Correct Answer:`time.sleep()`,pauses the program
time.sleep()
- 

pauses the program

Correct Answer:`string.ascii_letters`,provides all letters
string.ascii_letters
- 

provides all letters

Correct Answer:`string.digits`,provides all digits
string.digits
- 

provides all digits