random.normalvariate
function . normalvariate()
is an inbuilt method of the random
module. It is used to return a random floating point number with normal distribution.random.normalvariate(mu,sigma)
Parameter | Description |
---|---|
mu | Required. Mean. |
sigma | Required. Standard deviation. |
Example :
1.
# import the random moduleimport random# determining the values of the parametersmu = 100sigma = 50# using the normalvariate() methodprint(random.normalvariate(mu, sigma))
# import the required librariesimport randomimport matplotlib.pyplot as plt# store the random numbers in a# listnums = []mu = 100sigma = 50for i in range(100):temp = random.normalvariate(mu, sigma)nums.append(temp)# plotting a graphplt.plot(nums)plt.show()
Output :
# import the required librariesimport randomimport matplotlib.pyplot as plt# store the random numbers in a listnums = []mu = 100sigma = 50for i in range(10000):temp = random.normalvariate(mu, sigma)nums.append(temp)# plotting a graphplt.hist(nums, bins = 200)plt.show()
Output :
Comments