If you need a very long period random number generator, you should use SURXOR and DURXOR, rather than SURAND and DURAND, respectively. The very long period of the generator used by SURXOR and DURXOR, 21279-1, makes it useful in modern statistical simulations in which the shorter period of other generators can be exhausted during a single run. As a result, if you need a large number of random numbers, you can use these subroutines, because with this generator, you are not be requesting more than a small percentage of the entire period of the generator.
This section contains the random number generation subroutine descriptions.
These subroutines generate vector x of uniform (0,1)
pseudo-random numbers, using the multiplicative congruential method with a
user-specified seed.
x | seed | Subroutine |
Short-precision real | Long-precision real | SURAND |
Long-precision real | Long-precision real | DURAND |
Note: | If you need a very long period random number generator, use SURXOR and DURXOR instead of these subroutines. |
Fortran | CALL SURAND | DURAND (seed, n, x) |
C and C++ | surand | durand (seed, n, x); |
PL/I | CALL SURAND | DURAND (seed, n, x); |
Note: | seed is always a long-precision real number, even in SURAND. |
In your C program, argument seed must be passed by reference.
The uniform (0,1) pseudo-random numbers are generated as follows, using the multiplicative congruential method:
where:
See references [70] and [74]. If n is 0, no computation is performed, and the initial seed is unchanged.
None
This example shows a call to SURAND to generate 10 random numbers.
SEED N X | | | CALL SURAND( SEED , 10 , X ) SEED = 80629.0
Note: | It is important to note that SEED is a long-precision number, even though X contains short-precision numbers. |
SEED = 759150100.0 X = (0.6310323, 0.7603202, 0.7015232, 0.5014868, 0.4895853, 0.4602344, 0.1603608, 0.1832564, 0.9899062, 0.3535068)
This example shows a call to DURAND to generate 10 random numbers.
SEED N X | | | CALL DURAND( SEED , 10 , X ) SEED = 80629.0
SEED = 759150100.0 X = (0.6310323270182275, 0.7603201953509451, 0.7015232633340746, 0.5014868557925740, 0.4895853057920864, 0.4602344475967038, 0.1603607578018497, 0.1832563756887132, 0.9899062002030695, 0.3535068129904134)
These subroutines generate vector x of normally distributed
pseudo-random numbers, with a mean of 0 and a standard deviation of 1, using
Polar methods with a user-specified seed.
x, aux | seed | Subroutine |
Short-precision real | Long-precision real | SNRAND |
Long-precision real | Long-precision real | DNRAND |
Fortran | CALL SNRAND | DNRAND (seed, n, x, aux, naux) |
C and C++ | snrand | dnrand (seed, n, x, aux, naux); |
PL/I | CALL SNRAND | DNRAND (seed, n, x, aux, naux); |
Note: | seed is always a long-precision real number, even in SNRAND. |
If naux = 0 and error 2015 is unrecoverable, aux is ignored.
Otherwise, it is the storage work area used by this subroutine. Its size must be greater than or equal to n/2.
Specified as: an area of storage, containing numbers of the data type indicated in Table 164. They can have any value.
If naux = 0 and error 2015 is unrecoverable, SNRAND and DNRAND dynamically allocate the work area used by the subroutine. The work area is deallocated before control is returned to the calling program.
Otherwise, naux >= n/2.
The normally distributed pseudo-random numbers, with a mean of 0 and a standard deviation of 1, are generated as follows, using Polar methods with a user-specified seed. The Polar method, which this technique is based on, was developed by G. E. P. Box, M. E. Muller, and G. Marsaglia and is described in reference [70].
If pj >= 1, then pj is discarded, and steps 1 through 3 are repeated until pj < 1.
If n is 0, no computation is performed, and the initial seed is unchanged.
Error 2015 is unrecoverable, naux = 0, and unable to allocate work area.
None
This example shows a call to SNRAND to generate 10 random numbers.
SEED N X AUX NAUX | | | | | CALL SNRAND( SEED , 10 , X , AUX , 5 ) SEED = 80629.0
Note: | It is important to note that SEED is a long-precision number, even though X contains short-precision numbers. |
SEED = 48669425.0 X = (0.660649538, 1.312503695, 1.906438112, 0.014065863, -0.800935328, -3.058144093, -0.397426069, -0.370634943, -0.064151444, -0.275887042)
This example shows a call to DNRAND to generate 10 random numbers.
SEED N X AUX NAUX | | | | | CALL DNRAND( SEED , 10 , X , AUX , 5 ) SEED = 80629.0
SEED = 48669425.0 X = (0.6606495655963802, 1.3125037758861060, 1.9064381379483730, 0.0140658628770495, -0.8009353314494653, -3.0581441239248530, -0.3974260845722100, -0.3706349643478605, -0.0641514443372939, -0.2758870630332470)
These subroutines generate a vector x of uniform [0,1)
pseudo-random numbers, using the Tausworthe exclusive-or algorithm.
x, vseed
| iseed | Subroutine |
Short-precision real | Integer | SURXOR |
Long-precision real | Integer | DURXOR |
Fortran | CALL SURXOR | DURXOR (iseed, n, x, vseed) |
C and C++ | surxor | durxor (iseed, n, x, vseed); |
PL/I | CALL SURXOR | DURXOR (iseed, n, x, vseed); |
If iseed <> 0, iseed is the initial value used to generate the random numbers. You specify iseed <> 0 when you call this subroutine for the first time or when you changed vseed between calls to this subroutine.
If iseed = 0, vseed is used to generate the random numbers, where vseed was initialized by an earlier call to this subroutine. ESSL assumes you have not changed vseed between calls to this subroutine, when you specify iseed = 0.
Specified as: a fullword integer, as indicated in Table 165.
If iseed <> 0, vseed is not used for input. The work area can contain anything.
If iseed = 0, vseed contains the seed vector generated by a preceding call to this subroutine. vseed is used in this computation to generate the new random numbers. It should not be changed between calls to this subroutine.
Specified as: a one-dimensional array of (at least) length 10000, containing numbers of the data type indicated in Table 165.
The pseudo-random numbers uniformly distributed in the interval [0,1) are generated using the Tausworthe exclusive-or algorithm. This is based on a linear-feedback shift-register sequence. The very long period of the generator, 21279-1, makes it useful in modern statistical simulations where the shorter period of other generators could be exhausted during a single run. If you need a large number of random numbers, you can use these subroutines, because with this generator you do not request more than a small percentage of the entire period of the generator.
This generator is based on two feedback positions to generate a new binary digit:
where:
For details, see references [50], [68], and [88]. The values of p and q are selected according to the criteria stated in reference [94].
The algorithm initializes a seed vector of length p, starting with iseed. The seed vector is stored in vseed for use in subsequent calls to this subroutine with iseed = 0.
If n is 0, no computation is performed, and the initial seed is unchanged.
For some specialized applications, if you need multiple sources of random numbers, you can specify different vseed areas, which are initialized with different seeds on multiple calls to this subroutine. You then get multiple sequences of the random number sequence provided by the generator that are sufficiently far apart for most purposes.
None.
This example shows a call to SURXOR to generate 10 random numbers.
ISEED N X VSEED | | | | CALL SURXOR( ISEED , 10 , X , VSEED ) ISEED = 137
ISEED = 0 X = (0.6440868, 0.5105118, 0.4878680, 0.3209075, 0.6624528, 0.2499877, 0.0056630, 0.7329214, 0.7486335, 0.8050517)
This example shows a call to SURXOR to generate 10 random numbers. This example specifies iseed = 0 and uses the vseed output generated from Example 1.
ISEED N X VSEED | | | | CALL SURXOR( ISEED , 10 , X , VSEED ) ISEED = 0
ISEED = 0 X = (0.9930249, 0.0441873, 0.6891295, 0.3101060, 0.6324178, 0.3299408, 0.3553145, 0.0100013, 0.0214620, 0.8059390)
This example shows a call to DURXOR to generate 20 random numbers. This sequence of numbers generated are like those generated in Examples 1 and 2.
ISEED N X VSEED | | | | CALL DURXOR( ISEED , 20 , X , VSEED ) ISEED = 137
ISEED = 0 X = (0.64408693438956721, 0.51051182536460882, 0.48786801310787142, 0.32090755617007050, 0.66245283144861666, 0.24998782843358081, 0.00566308101257373, 0.73292147005172925, 0.74863359794102236, 0.80505169697755319, 0.99302499462139138, 0.04418740640269125, 0.68912952155409579, 0.31010611495627916, 0.63241786342211936, 0.32994081459690583, 0.35531452631408911, 0.01000134413132581, 0.02146199494672940, 0.80593898487597615)