Products & Services Solutions Academia Support User Community Company

Learn more about Statistics Toolbox   

randg - Gamma random numbers

Syntax

Y = randg
Y = randg(A)
Y = randg(A,m)
Y = randg(A,m,n,...)
Y = randg(A,[m,n,...])

Description

Y = randg returns a scalar random value chosen from a gamma distribution with unit scale and shape.

Y = randg(A) returns a matrix of random values chosen from gamma distributions with unit scale. Y is the same size as A, and randg generates each element of Y using a shape parameter equal to the corresponding element of A.

Y = randg(A,m) returns an m-by-m matrix of random values chosen from gamma distributions with shape parameters A. A is either an m-by-m matrix or a scalar. If A is a scalar, randg uses that single shape parameter value to generate all elements of Y.

Y = randg(A,m,n,...) or Y = randg(A,[m,n,...]) returns an m-by-n-by-... array of random values chosen from gamma distributions with shape parameters A. A is either an m-by-n-by-... array or a scalar.

randg produces pseudo-random numbers using the MATLAB functions rand and randn. The sequence of numbers generated is determined by the state of the default random number stream. Since MATLAB resets the state at start-up, the sequence of numbers randg generates will be the same in each session unless those states are changed.

To create reproducible output from randg, reset the state of the default stream before calling randg. For example:

reset(RandStream.getDefaultStream,0);
r = randg(1,[10,1]); 

always produces the same 10 values. See the RandStream documentation for more information.

Calling randg changes the current states of rand, randn, and randi, and therefore alters the outputs of subsequent calls to those functions.

To generate gamma random numbers and specify both the scale and shape parameters, you should call gamrnd rather than calling randg directly.

References

[1] Marsaglia, G., and W. W. Tsang. "A Simple Method for Generating Gamma Variables." ACM Transactions on Mathematical Software. Vol. 26, 2000, pp. 363–372.

See Also

gamrnd

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS