DRANDINITIALIZE / SRANDINITIALIZE
Initialize one of the five supplied base generators; NAG basic generator, Wichmann-Hill generator, Mersenne Twister, L'Ecuyer's combined recursive generator (MRG32k3a) or the Blum-Blum-Shub generator.
(Note that SRANDINITIALIZE is the single precision version of DRANDINITIALIZE. The argument lists of both routines are identical except that any double precision arguments of DRANDINITIALIZE are replaced in SRANDINITIALIZE by single precision arguments - type REAL in FORTRAN or type float in C).
— Input: INTEGER GENID
On input: a numerical code indicating which of the five base generators to initialize.
- 1 = NAG basic generator (Basic NAG Generator).
- 2 = Wichmann-Hill generator (Wichmann-Hill Generator).
- 3 = Mersenne Twister (Mersenne Twister).
- 4 = L'Ecuyer's Combined Recursive generator (L'Ecuyer's Combined Recursive Generator).
- 5 = Blum-Blum-Shub generator (Blum-Blum-Shub Generator).
Constraint: 1<=GENID <=5.— Input: INTEGER SUBID
On input: if GENID=2, then SUBID indicates which of the 273 Wichmann-Hill generators to use. If GENID=5 then SUBID indicates the number of bits to use (v) from each of iteration of the Blum-Blum-Shub generator. In all other cases SUBID is not referenced.
Constraint: If GENID=2 then 1<=SUBID <=273 .— Input: INTEGER SEED(LSEED)
On input: if GENID is not equal to 5 , then SEED is a vector of initial values for the base generator. These values must be positive integers. The number of values required depends on the base generator being used. The NAG basic generator requires one initial value, the Wichmann-Hill generator requires four initial values, the L'Ecuyer combined recursive generator requires six initial values and the Mersenne Twister requires 624 initial values. If the number of seeds required by the chosen generator is >LSEED then SEED(1) is used to initialize the NAG basic generator. This is then used to generate all of the remaining seed values required. In general it is best not to set all the elements of SEED to anything too obvious, such as a single repeated value or a simple sequence. Using such a seed array may lead to several similar values being created in a row when the generator is subsequently called. This is particularly true for the Mersenne Twister generator.
In order to initialize the Blum-Blum-Shub generator two large prime values, p and q are required as well as an initial value s. As p, q and s can be of an arbitrary size, these values are factored into a expressed as a polynomial in B, where B=2^(24). For example, p can be factored into a polynomial of order l_p, with p = p_1 + p_2B + p_3B^2 + ... + p_(l_p) * B^(l_p-1). The elements of SEED should then be set to the following:
- SEED(1) = l_p
- SEED(2) to SEED(l_p+1) = p_1 to p_(l_p)
- SEED(l_p+2) = l_q
- SEED(l_p+3) to SEED(l_p+l_q+2) = q_1 to q_(l_q)
- SEED(l_p+l_q+3) = l_s
- SEED(l_p+l_q+4) to SEED(l_p+l_q+l_s+3) = s_1 to s_(l_s)
Constraint: If GENID is not equal to 5 then SEED(i)>0 for i=1,2,.... If GENID=5 then SEED must take the values described above.— Input/Output: INTEGER LSEED
On input: either the length of the seed vector, SEED, or a value <=0 .
On output: if LSEED<=0 on input, then LSEED is set to the number of initial values required by the selected generator, and the routine returns. Otherwise LSEED is left unchanged.— Output: INTEGER STATE(LSTATE)
On output: the state vector required by all of the supplied distributional and base generators.
— Input/Output: INTEGER LSTATE
On input: either the length of the state vector, STATE, or a value <=0 .
On output: if LSTATE<=0 on input, then LSTATE is set to the minimum length of the state vector STATE for the base generator chosen, and the routine returns. Otherwise LSTATE is left unchanged.
Constraint: LSTATE<=0 or the minimum length for the chosen base generator, given by:
- GENID=1: LSTATE>=16,
- GENID=2: LSTATE>=20,
- GENID=3: LSTATE>=633,
- GENID=4: LSTATE>=61,
- GENID=5: LSTATE>=l_p+l_q+l_s+6 , where l_p, l_q and l_s are the order of the polynomials used to express the parameters p,q and s respectively.
— Output: INTEGER INFO
On output: INFO is an error indicator. If INFO = -i on exit, the i-th argument had an illegal value. If INFO =1 on exit, then either, or both of LSEED and / or LSTATE have been set to the required length for vectors SEED and STATE respectively. Of the two variables LSEED and LSTATE, only those which had an input value <=0 will have been set. The STATE vector will not have been initialized. If INFO = 0 then the state vector, STATE, has been successfully initialized.
Example:
C Generate 100 values from the Beta distribution INTEGER LSTATE,N PARAMETER (LSTATE=16,N=100) INTEGER I,INFO,SEED(1),STATE(LSTATE) DOUBLE PRECISION A,B DOUBLE PRECISION X(N) C Set the seed SEED(1) = 1234 C Read in the distributional parameters READ(5,*) A,B C Initialize the STATE vector CALL DRANDINITIALIZE(1,1,SEED,1,STATE,LSTATE,INFO) C Generate N variates from the Beta distribution CALL DRANDBETA(N,A,B,STATE,X,INFO) C Print the results WRITE(6,*) (X(I),I=1,N) |