all Python 3randomfunction
random.weibullvariate
distributions
A random number from the Weibull distribution (scale alpha, shape beta); always non-negative.
Syntax
random.weibullvariate(alpha, beta)
The argument order trips people up: scale alpha comes first, shape beta second, whereas textbooks and scipy usually put the shape first — swap them and you still get plausible-looking numbers that are simply wrong. At beta = 1 the distribution collapses to an exponential with mean alpha, and as beta grows the values cluster ever more tightly around alpha, which is why it is the standard choice for modelling wear-out and time to failure.
Examples
import random
print(random.weibullvariate(1.0, 1.0) >= 0.0) # → True
print(round(sum(random.weibullvariate(2.0, 1.0) for _ in range(50000)) / 50000)) # → 2
print(abs(random.weibullvariate(10.0, 200.0) - 10.0) < 2.0) # → True
print(round(sum(random.weibullvariate(1.0, 1.0) > 1.0 for _ in range(50000)) / 50000, 1)) # → 0.4
print(random.weibullvariate(1.0, 0.0)) # → ZeroDivisionError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy