Random number functions in Python
Generally, Random numbers are used to generate Random numbers. These random numbers are used to make games, testing, and automation systems. We can see the real example of the function when we get the captcha or OTP it is done by a random function which is different in different programming languages.
1.choice()
The choice function in Python will return the random item from the list, string, or tuple.
import random
print "choice([1, 2, 3, 5, 9, 4]) : ", random.choice([1, 2, 3, 5, 9, 4])
print "choice('Happy Diwali ') : ", random.choice('Happy Diwali ')
2.random()
This function returns the random float value between 0 and 1.
import random
# First random number example
print "random() : ", random.random()
# Second random number example
print "random() : ", random.random()
3.shuffle()
This method will return the shuffled relief from the list.
import random
#First example
list = [45, 16, 10, 5, 65];
random.shuffle(list)
print "Reshuffled list : ", list
#Second example
random.shuffle(list)
print "Reshuffled list : ", list
4.uniform()
The uniform function will return the random float value. The uniform function will take two arguments in the form of X and Y where the value will be less than or equal to X hand less than by accordingly.
import random
print "Random Float uniform(2, 10) : ", random.uniform(2, 10)
print "Random Float uniform(4, 14) : ", random.uniform(4, 14)
