Up: Leap Frogging


DRANDLEAPFROG / SRANDLEAPFROG

Amend a generator so that it will generate every Kth value.

(Note that SRANDLEAPFROG is the single precision version of DRANDLEAPFROG. The argument lists of both routines are identical except that any double precision arguments of DRANDLEAPFROG are replaced in SRANDLEAPFROG by single precision arguments - type REAL in FORTRAN or type float in C).

— SUBROUTINE: DRANDLEAPFROG (N,K,STATE,INFO)
— Input: INTEGER N

On input: total number of streams being used.
Constraint: N>0.

— Input: INTEGER K

On input: number of the current stream
Constraint: 0<K <=N.

— Input/Output: INTEGER STATE(*)

The STATE vector holds information on the state of the base generator being used and as such its minimum length varies. Prior to calling DRANDLEAPFROG STATE must have been initialized. See Initialization of the Base Generators for information on initialization of the STATE variable.
On input: the current state of the base generator.


On output: The STATE vector for a generator that has been advanced K-1 places and will return every Nth value.
Constraint: The STATE array must be for either the NAG basic, Wichmann-Hill or L'Ecuyer Combined Recursive base generators.

— Output: INTEGER INFO

On output: INFO is an error indicator. On successful exit, INFO contains 0. If INFO = -i on exit, the i-th argument had an illegal value.

Example:

     C     Generate 3 * 100 values from the Uniform distribution
     C     Multiple streams generated using the Leap Frog method
           INTEGER LSTATE,N
           PARAMETER (LSTATE=16,N=100)
           INTEGER I,INFO
           INTEGER SEED(1),STATE1(LSTATE),STATE2(LSTATE),STATE3(LSTATE)
           INTEGER  X1(N),X2(N),X3(N)
           DOUBLE PRECISION A,B
     
     C     Set the seed
           SEED(1) = 1234
     
     C     Set the distributional parameters
           A = 0.0D0
           B = 1.0D0
     
     C     Initialize the STATE1 vector
           CALL DRANDINITIALIZE(1,1,SEED,1,STATE1,LSTATE,INFO)
     
     C     Copy the STATE1 vector into other state vectors
           DO 20 I = 1,LSTATE
             STATE2(I) = STATE1(I)
             STATE3(I) = STATE1(I)
     20    CONTINUE
     
     C     Update each stream so they generate every 3rd value
           CALL DRANDLEAPFROG(3,1,STATE1,INFO)
           CALL DRANDLEAPFROG(3,2,STATE2,INFO)
           CALL DRANDLEAPFROG(3,3,STATE3,INFO)
     
     C     Generate 3 sets of N variates from the Univariate distribution
           CALL DRANDUNIFORM(N,A,B,STATE1,X1,LDX,INFO)
           CALL DRANDUNIFORM(N,A,B,STATE2,X2,LDX,INFO)
           CALL DRANDUNIFORM(N,A,B,STATE3,X3,LDX,INFO)
     
     C     Print the results
           DO 40 I = 1,N
             WRITE(6,*) X1(I),X2(I),X3(I)
     40    CONTINUE