25  The Random Library

Python’s random library contains a number of functions that allow us to generate random numbers. This is useful in modelling, because we’re going to need random numbers if we’re to build stochastic models.

Remember we talked about probability distributions in session 1B?

To import the random library, we use the following at the start of our code (we don’t need to install random, as it comes with the Anaconda distribution of Python) :

Important

You need to run the cell above first, otherwise the examples further down this page won’t work!

Tip

Try running the cells below multiple times - you will see that you get a different output each time!