Full name
random.gammavariate
Library
random
Syntax
random.gammavariate(alpha, beta)
Description
The random.gammavariate function returns a random number drawn from a gamma distribution.
Parameters
- alpha, beta: Parameters of the gamma function. Both must be greater than zero.
Result
The random.gammavariate function returns a real number.
Examples
We can generate a random number extracted from a gamma distribution defined by the parameters alpha = 5 and beta = 1 with the following code:
random.gammavariate(5, 1)
5.021679946701151
To confirm the distribution from which the random numbers are extracted we can generate 10 thousand random numbers from a gamma distribution defined by the parameters alpha = 5 and beta = 1 and show its histogram:
import matplotlib.pyplot as plt
plt.figure(figsize = (8, 4))
plt.hist([random.gammavariate(5, 1) for i in range(100000)], bins = 100)
plt.show()
plt.hist([random.gammavariate(5, 1) for i in range(100000)], bins = 100)
plt.show()