Why am I unable to reproduce the random numbers generated by the GAMRND function in the Statistics Toolbox?

2 views (last 30 days)
I set the state of RAND before calling GAMRND. However the output is not reproduced. Below is a function that illustrates the issue:
function testgamma
state = 0
rand('state', state);
n1 = gamrnd(1,1)
Calling "testgamma.m" repeatedly does not result in the same set of random numbers generated.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This change has been incorporated into the documentation in Release 14 Service Pack 3 (R14SP3). For previous releases, read below for any additional information:
We have verified that the documentation for reproducing outputs of random number generator functions in the Statistics Toolbox is incomplete.
To reproduce the output of GAMRND, you need to set the state of both RAND and RANDN. Below is an example to illustrate this:
state = 0
rand('state', state);
randn('state', state);
n1 = gamrnd(1,1)

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!