| Statistics Toolbox™ | ![]() |
Y = randg
Y = randg(A)
Y = randg(A,m)
Y = randg(A,m,n,...)
Y = randg(A,[m,n,...])
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 pseudorandom numbers using the MATLAB® functions rand and randn. The sequence of numbers generated is determined by the states of both generators. To create reproducible output from randg, set the states of both rand and randn to a fixed pair of values before calling randg. For example,
rand('state',j);
randn('state',s);
r = randg(1,[10,1]);always generates the same 10 values. You can also use the MATLAB generators by calling rand and randn with the argument 'seed'. Calling randg changes the current states of rand and randn 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.
[1] Marsaglia, G., and Tsang, W. W., "A Simple Method for Generating Gamma Variables," ACM Transactions on Mathematical Software, Vol. 26, 2000, pp. 363-372.
![]() | quantile | random | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |