One of the most common problems you face when writing certain types of applications is the
need to generate random numbers. Rolling dice is one of the most popular uses for random
number generation as all players of Dungeons and Dragons™ will tell you, but there are quite
a few uses for this functionality in the corporate world as well. Imagine, for example, that you
want to show a user a security question each time he logs in to your corporate network, but
you don’t want him to know which question he will have to answer. There might be 10 questions,
and you want the questions presented in a random order, so that the user can’t get too
complacent. This is an excellent place for random number generation.
The Python random module provides functionality for the production and control of random
numbers. Besides the capability to generate simple random numbers, the module also provides
methods for seeding the random number generator, selecting a random entry from any sequence,
and quite a few other bits of functionality. Let’s take a look at some of the uses now.