What this tool does
This generator produces a list of pseudo-random numbers that follow a Gamma distribution with a chosen shape parameter a and scale parameter b. The Gamma distribution is a continuous, strictly positive distribution widely used in reliability engineering, queueing theory, Bayesian statistics (as a conjugate prior), rainfall and insurance modeling, and anywhere waiting times or positive skewed quantities appear. It is a universal mathematical tool and is not specific to any country.
How to use it
Enter the shape parameter a (must be greater than 0), the scale parameter b (must be greater than 0), and how many values you want (1 to 1000). Choose how many significant digits to display. Press calculate to receive an ordered list of draws plus the sample mean and variance, shown alongside the theoretical mean and variance so you can sanity-check the output.
The formula
The density is $$f(x; a, b) = \frac{1}{\Gamma(a)\cdot b} \cdot \left(\frac{x}{b}\right)^{a-1} \cdot e^{-x/b}, \quad x > 0,$$ where \(\Gamma(a)\) is the gamma function. In this scale parameterization the mean is \(a\cdot b\) and the variance is \(a\cdot b^2\). Note that \(b\) is a scale, not a rate; if another library uses rate \(\lambda = 1/b\), set \(b = 1/\lambda\). Sampling uses the Marsaglia-Tsang squeeze method for \(a \ge 1\), with a power-of-uniform boost for \(a < 1\). Each unit-scale draw is multiplied by \(b\) to apply the scale.
Worked example
With \(a = 3\), \(b = 1\), count = 10, every value is a Gamma(3,1) sample. The theoretical mean is \(a\cdot b = 3\) and the theoretical variance is \(a\cdot b^2 = 3\) (std \(\approx 1.732\)). A plausible draw set might average near 3 with spread around 1.7. Changing to \(a = 2\), \(b = 5\) gives a mean of 10 and variance of 50; values remain strictly positive.
FAQ
Why do the numbers change every time? The output is random, so unless a fixed seed is used the values differ each run. The sample mean and variance should stay close to the theoretical values.
What if a = 1? Gamma(1, b) is the Exponential distribution with mean \(b\). Integer values of \(a\) give the Erlang distribution.
Is b a rate or a scale? It is a scale. The mean equals \(a\cdot b\), so larger \(b\) stretches the distribution to larger values.