randg
Gamma distributed random number.
📝Syntax
M = randg
M = randg(A)
M = randg(A, n)
M = randg(A, x1, x2, ... , xN)
M = randg(A, sz)
M = randg(A, x1, x2, ... , xN, classname)
📥Input Arguments
Parameter Description
A a real nonnegative value or array: the shape parameter(s).
n a variable: n-by-n matrix will be generated.
x1, x2, ... , xN x1-by-...-by-xN values
classname a string: 'single' or 'double'
📤Output Arguments
Parameter Description
M a matrix of random numbers.
📄Description

randg returns a matrix with gamma distributed random elements, with shape parameter A and unit scale.

A gamma sample of shape k has mean k and variance k; a shape of 1 gives the standard exponential distribution.

When only A is supplied, the result has the size of A and each element uses the matching shape. When a size is supplied, A must be a scalar used for every element.

Values are drawn with the Marsaglia and Tsang rejection method; the seed can be modified using rng.

💡Examples
rng('default');
randg
rng('default');
randg(2, 3)
rng('default');
M = randg(3, 1, 100000);
[mean(M), var(M)]
rng('default');
randg(2, 2, 2, 'single')
🔗See Also
randrandnrng
📚Bibliography
G. Marsaglia and W. W. Tsang, "A simple method for generating gamma variables", ACM Transactions on Mathematical Software, 26(3), 363-372, 2000.
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub