Locked lesson.
About this lesson
In this lesson, we'll show how to generate random numbers.
Exercise files
Download this lesson’s related exercise files.
11 - Random Numbers.docx57.1 KB 11 - Random Numbers SOLUTION.docx
55.6 KB
Quick reference
Random Numbers
Random Numbers are easy to generate using Python.
When to use
Do this whenever you need to generate dummy data.
Instructions
First, we need to import the random library into our program:
from random import random
from random import randint
To create a random number (decimal):
random()
To Create a random integer between 0 an 10:
randint(0,10)
Hints & tips
- from random import random
- random()
- from random import randint
- randint(0,10)
Lesson notes are only available for subscribers.