Full name
random.gauss
Library
random
Syntax
random.gauss(mu, sigma)
Description
The random.gauss function returns a random number drawn from a Gaussian distribution.
Parameters
- mu: Mean of the distribution.
- sigma: Standard deviation of the distribution.
Result
The random.gauss function returns a real number.
Examples
We can generate a random number extracted from a Gaussian distribution with mean 5 and standard deviation 3 with the following code:
random.gauss(5, 3)
2.8795350224332856
To confirm the distribution from which the random numbers are extracted, we can generate one hundred thousand random numbers from a Gaussian distribution with mean 5 and standard deviation 3 and show their histogram:
import matplotlib.pyplot as plt
plt.figure(figsize = (8, 4))
plt.hist([random.gauss(5, 3) for i in range(100000)], bins = 100)
plt.grid()
plt.show()
plt.hist([random.gauss(5, 3) for i in range(100000)], bins = 100)
plt.grid()
plt.show()