XLPack 7.0
XLPack Numerical Library (C API) Reference Manual
Loading...
Searching...
No Matches

◆ rgama_r()

void rgama_r ( double  alpha,
double  beta,
double *  r,
double  yy,
int *  irev 
)

Generate random numbers following gamma distribution (Squeeze method of Marsaglia and Tsang) (reverse communication version)

Purpose
This routine generates random numbers following gamma distribution Γ(α, β).
The given normal and uniform random numbers are transformed to the gamma random numbers by the squeeze method of Marsaglia and Tsang.
Parameters
[in]alphaThe shape parameter α of the gamma distribution Γ(α, β). (α > 0)
[in]betaThe rate parameter β of the gamma distribution Γ(α, β). (β > 0)
[out]rGamma random number. (> 0)
If alpha or beta is not valid, 0 will be returned.
[in]yyirev = 1: The normal random number should be given in the next call. irev = 2, 3: The uniform random number in the interval (0, 1) should be given in the next call.
[in,out]irevControl variable for reverse communication.
[in] Before first call, irev should be initialized to zero. On succeeding calls, irev should not be altered.
[out] If irev is not zero, complete the following tasks and call this routine again without changing irev.
= 0: Computation finished.
= 1: User should set the normal random number in yy. Do not alter any variables other than yy. = 2, 3: User should set the uniform random number in the interval (0, 1) in yy. Do not alter any variables other than yy.
Reference
Yatsuji Tetsuaki, "Probability distribution random number generation method" 2nd ed., Pleiades Publishing, 2019. (Japanese book)