random.expovariate
function. expovariate()
is an inbuilt method of the random
module. It is used to return a random float number based on the Exponential distribution (used in statistics).random.expovariate(lambd)
Parameter | Description |
---|---|
lambd | Required. A non-zero value. |
Example :
1.
# import the random moduleimport random# determining the values of the parameterlambd = 1.5# using the expovariate() methodprint(random.expovariate(lambd))
Output :
0.32035158577123574
2.
# import the required librariesimport randomimport matplotlib.pyplot as plt# store the random numbers in a# listnums = []lambd = 3for i in range(100):temp = random.expovariate(lambd)nums.append(temp)# plotting a graphplt.plot(nums)plt.show()
Output :
3.
# import the required librariesimport randomimport matplotlib.pyplot as plt# store the random numbers in a listnums = []lambd = 1.5for i in range(10000):temp = random.expovariate(lambd)nums.append(temp)# plotting a graphplt.hist(nums, bins = 200)plt.show()
Output :
*****END OF ARTICLE*****
Comments