14
Library of Fortran Routines for Random Number Generation
23
Base Generator Documentation
32
Compiled and Written by:
46
Department of Biomathematics, Box 237
47
The University of Texas, M.D. Anderson Cancer Center
48
1515 Holcombe Boulevard
52
This work was supported by grant CA-16672 from the National Cancer Institute.
57
Base Random Number Generator
61
I. OVERVIEW AND DEFAULT BEHAVIOR
63
This set of programs contains 32 virtual random number generators.
64
Each generator can provide 1,048,576 blocks of numbers, and each block
65
is of length 1,073,741,824. Any generator can be set to the beginning
66
or end of the current block or to its starting value. The methods are
67
from the paper cited immediately below, and most of the code is a
68
transliteration from the Pascal of the paper into Fortran.
70
P. L'Ecuyer and S. Cote. Implementing a Random Number Package with
71
Splitting Facilities. ACM Transactions on Mathematical Software 17:1,
74
Most users won't need the sophisticated capabilities of this package,
75
and will desire a single generator. This single generator (which will
76
have a non-repeating length of 2.3 X 10^18 numbers) is the default.
77
In order to accommodate this use, the concept of the current generator
78
is added to those of the cited paper; references to a generator are
79
always to the current generator. The current generator is initially
80
generator number 1; it can be changed by SETCGN, and the ordinal
81
number of the current generator can be obtained from GETCGN.
83
The user of the default can set the initial values of the two integer
84
seeds with SETALL. If the user does not set the seeds, the random
85
number generation will use the default values, 1234567890 and
86
123456789. The values of the current seeds can be achieved by a call
87
to GETSD. Random number may be obtained as integers ranging from 1 to
88
a large integer by reference to function IGNLGI or as a floating point
89
number between 0 and 1 by a reference to function RANF. These are the
90
only routines needed by a user desiring a single stream of random
95
A stream of pseudo-random numbers is a sequence, each member of which
96
can be obtained either as an integer in the range 1..2,147,483,563 or
97
as a floating point number in the range [0..1]. The user is in charge
98
of which representation is desired.
100
The method contains an algorithm for generating a stream with a very
101
long period, 2.3 X 10^18. This stream in partitioned into G (=32)
102
virtual generators. Each virtual generator contains 2^20 (=1,048,576)
103
blocks of non-overlapping random numbers. Each block is 2^30
104
(=1,073,741,824) in length.
108
Base Random Number Generator Page 2
111
The state of a generator is determined by two integers called seeds.
112
The seeds can be initialized by the user; the initial values of the
113
first must lie between 1 and 2,147,483,562, that of the second between
114
1 and 2,147,483,398. Each time a number is generated, the values of
115
the seeds change. Three values of seeds are remembered by the
116
generators at all times: the value with which the generator was
117
initialized, the value at the beginning of the current block, and the
118
value at the beginning of the next block. The seeds of any generator
119
can be set to any of these three values at any time.
121
Of the 32 virtual generators, exactly one will be the current
122
generator, i.e., that one will be used to generate values for IGNLGI
123
and RANDF. Initially, the current generator is set to number one.
124
The current generator may be changed by calling SETCGN, and the number
125
of the current generator can be obtained using GETCGN.
129
An example of the need for these capabilities is as follows. Two
130
statistical techniques are being compared on data of different sizes.
131
The first technique uses bootstrapping and is thought to be as
132
accurate using less data than the second method which employs only
135
For the first method, a data set of size uniformly distributed between
136
25 and 50 will be generated. Then the data set of the specified size
137
will be generated and alalyzed. The second method will choose a data
138
set size between 100 and 200, generate the data and alalyze it. This
139
process will be repeated 1000 times.
141
For variance reduction, we want the random numbers used in the two
142
methods to be the same for each of the 1000 comparisons. But method
143
two will use more random numbers than method one and without this
144
package, synchronization might be difficult.
146
With the package, it is a snap. Use generator 1 to obtain the sample
147
size for method one and generator 2 to obtain the data. Then reset
148
the state to the beginning of the current block and do the same for
149
the second method. This assures that the initial data for method two
150
is that used by method one. When both have concluded, advance the
151
block for both generators.
155
A random number is obtained either as a random integer between 1 and
156
2,147,483,562 by invoking integer function IGNLGI (I GeNerate LarGe
157
Integer) or as a random floating point number between 0 and 1 by
158
invoking real function RANF. Neither function has arguments.
160
The seed of the first generator can be set by invoking subroutine
161
SETALL; the values of the seeds of the other 31 generators are
162
calculated from this value.
166
Base Random Number Generator Page 3
169
The number of the current generator can be set by calling subroutine
170
SETCGN, which takes a single argument, the integer generator number in
171
the range 1..32. The number of the current generator can be obtained
172
by invoking subroutine GETCGN which returns the number in its single
178
A. SETTING THE SEED OF ALL GENERATORS
180
C**********************************************************************
182
C SUBROUTINE SETALL(ISEED1,ISEED2)
183
C SET ALL random number generators
185
C Sets the initial seed of generator 1 to ISEED1 and ISEED2. The
186
C initial seeds of the other generators are set accordingly, and
187
C all generators states are set to these seeds.
192
C ISEED1 -> First of two integer seeds
195
C ISEED2 -> Second of two integer seeds
198
C**********************************************************************
201
B. OBTAINING RANDOM NUMBERS
203
C**********************************************************************
205
C INTEGER FUNCTION IGNLGI()
206
C GeNerate LarGe Integer
208
C Returns a random integer following a uniform distribution over
209
C (1, 2147483562) using the current generator.
211
C**********************************************************************
213
C**********************************************************************
215
C REAL FUNCTION RANF()
216
C RANDom number generator as a Function
218
C Returns a random floating point number from a uniform distribution
219
C over 0 - 1 (endpoints of this interval are not returned) using the
222
C**********************************************************************
226
Base Random Number Generator Page 4
229
C. SETTING AND OBTAINING THE NUMBER OF THE CURRENT GENERATOR
231
C**********************************************************************
233
C SUBROUTINE SETCGN( G )
236
C Sets the current generator to G. All references to a generator
237
C are to the current generator.
241
C G --> Number of the current random number generator (1..32)
244
C**********************************************************************
246
C**********************************************************************
248
C SUBROUTINE GETCGN(G)
251
C Returns in G the number of the current random number generator
255
C G <-- Number of the current random number generator (1..32)
258
C**********************************************************************
260
D. OBTAINING OR CHANGING SEEDS IN CURRENT GENERATOR
262
C**********************************************************************
264
C SUBROUTINE ADVNST(K)
267
C Advances the state of the current generator by 2^K values and
268
C resets the initial seed to that value.
273
C K -> The generator is advanced by 2^K values
276
C**********************************************************************
280
Base Random Number Generator Page 5
283
C**********************************************************************
285
C SUBROUTINE GETSD(ISEED1,ISEED2)
288
C Returns the value of two integer seeds of the current generator
294
C ISEED1 <- First integer seed of generator G
297
C ISEED2 <- Second integer seed of generator G
300
C**********************************************************************
302
C**********************************************************************
304
C SUBROUTINE INITGN(ISDTYP)
305
C INIT-ialize current G-e-N-erator
307
C Reinitializes the state of the current generator
312
C ISDTYP -> The state to which the generator is to be set
313
C ISDTYP = -1 => sets the seeds to their initial value
314
C ISDTYP = 0 => sets the seeds to the first value of
316
C ISDTYP = 1 => sets the seeds to the first value of
321
C**********************************************************************
323
C**********************************************************************
325
C SUBROUTINE SETSD(ISEED1,ISEED2)
326
C SET S-ee-D of current generator
328
C Resets the initial seed of the current generator to ISEED1 and
329
C ISEED2. The seeds of the other generators remain unchanged.
334
C ISEED1 -> First integer seed
337
C ISEED2 -> Second integer seed
340
C**********************************************************************
344
Base Random Number Generator Page 6
349
C**********************************************************************
351
C INTEGER FUNCTION MLTMOD(A,S,M)
353
C Returns (A*S) MOD M
361
C**********************************************************************
363
C**********************************************************************
365
C SUBROUTINE SETANT(QVALUE)
368
C Sets whether the current generator produces antithetic values. If
369
C X is the value normally returned from a uniform [0,1] random
370
C number generator then 1 - X is the antithetic value. If X is the
371
C value normally returned from a uniform [0,N] random number
372
C generator then N - 1 - X is the antithetic value.
374
C All generators are initialized to NOT generate antithetic values.
378
C QVALUE -> .TRUE. if generator G is to generating antithetic
379
C values, otherwise .FALSE.
382
C**********************************************************************