Learn Python – Python Random module- Basic and advance

The Python random module features depend on a pseudo-random wide variety generator characteristic random(), which generates the waft variety between 0 and 1.0.

There are exceptional kinds of features used in a random module which is given below:


This feature generates a random go with the flow number between 0 and 1.0.


This feature returns a random integer between the particular integers.


This function returns a randomly chosen factor from a non-empty sequence.


# importing "random"  module.  
import random  
# We are using the choice() function to generate a random number from  
# the given list of numbers.  
print ("The random number from list is : ",end="")  
print (random.choice([50, 41, 84, 40, 31]))  


The random number from list is : 84


This feature randomly reorders the elements in the list.


This characteristic is used to generate a number inside the vary specified in its argument. It accepts three arguments, commencing number, closing number, and step, which is used to bypass a number in the range. Consider the following example.

# We are using randrange() function to generate in range from 100  
# to 500. The last parameter 10 is step size to skip  
# ten numbers when selecting.  
import random  
print ("A random number from range is : ",end="")  
print (random.randrange(100, 500, 10))  


A random number from range is : 290


This feature is used to follow on the particular random wide variety with the seed argument. It returns the mapper value. Consider the following example.

# importing "random" module.  
import random  
# using random() to generate a random number  
# between 0 and 1  
print("The random number between 0 and 1 is : ", end="")  
# using seed() to seed a random number  


The random number between 0 and 1 is : 0.4405576668981033