The random module is one of the most interesting module available in python. As the name suggests, this module produces all the random characters.

We can produce a random number between two given numbers and if just 1 argument is passed in, the start would be taken as 0 and the end as the given parameter.

We can have a random character choice in a given string, list, tuple etc and many more features but before using any function, we will have to import the module. To import the random module, we use the following command:

import random

Here are some function of random with examples.

Random number

We use random.randint(x,y) where x is the start and y is the end.

Random character

We can derive a random character from a given string.


x here is the population(sample from which the random module can derive the characters.)

Random sample

Random sample is personally, my favorite. This function provides a list of specific number of values from a specific population. To use this function, we type:

random.sample(population, number)

These are all the basic and the most important functions in this module. You can learn about them here