teach-ict.com logo

THE education site for computer science and ICT

3. Import Random

A Python 'module' contains a set of functions and procedures.

A large collection of modules are available as part of the standard Python installation. We will be using the 'random' module, which as its name suggests, is used for creating random numbers.

Follow the steps below using your local copy of Python:

Task 1a

Create a new Python file - called random_floats.py

Task 1b

You can import the entire random module by typing:

                  import random

However, we will be using just two of the functions from this module, random() and sample(). Type the following:

                  from random import random, sample

The file is shown loaded into our IDE below (lines starting with # are comments)


Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: Python random module