all Python 3randomfunction
random.normalvariate
distributions
A random number from the normal (Gaussian) distribution with mean mu and stddev sigma.
Syntax
random.normalvariate(mu=0.0, sigma=1.0)
It differs from gauss in implementation, not in distribution: normalvariate keeps no state between calls, so it is safe when several threads draw at once, at the cost of being slightly slower. The defaults mu=0.0 and sigma=1.0 arrived in Python 3.11; on older versions both arguments are required.
Examples
# Python 3.11+
import random
print(isinstance(random.normalvariate(0.0, 1.0), float)) # → True
print(isinstance(random.normalvariate(), float)) # → True
print(random.normalvariate(5.0, 0.0)) # → 5.0
sample = [random.normalvariate(100.0, 15.0) for _ in range(10000)]
print(90.0 < sum(sample) / len(sample) < 110.0) # → True
print(isinstance(random.gauss(0.0, 1.0), float)) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy