Although nearly everything the random module does is based on obtaining a single random number, the module provides us with a number of convenience functions, that take the tedium from doing common 'random' tasks. Functions are provided which return random integers in given ranges, random choices from sequences, or produce random permutations of a sequence. In addition there are some fairly useful distribution functions, which pull random number from chosen distributions with specified parameters.
Let's deal with the integers first.
random.randrange([start,] <stop>[, step])
returns a single random integer from start to
stop-1. If start is not specified, it defaults to
0. If step is specified, only integers in increments of
step from start will be chosen.random.randint(<start>, <stop>)
returns a single random integer from start to
stop (inclusive).The true convenience of the random module becomes apparent with the three sequence functions.
random.choice(<sequence>)
returns a single
random element from the sequencerandom.shuffle(<sequence>)
shuffles the
elements in sequence, in place, so they are in random order.random.sample(<sequence>, <k>)
returns
k randomly chosen elements from the sequence. This is
sampling without replacement, i.e. a single element from the
sequence can be chosen at most once.