RANDOM_TABLE Procedure
Sets or retrieves the current table used in either the shuffled or GFSR random number generator.
Usage
RANDOM_TABLE, table, /Get
RANDOM_TABLE, table, /Set
Input/Output Parameters
table—One dimensional array used in the generators. For the shuffled generators table is length 128. For the GFSR generator table is length 1565. For either MT generator, the table is a 625 element array of LONG integers. The argument table is input if the keyword Set is used, and output if the keyword Get is used.
Input Keywords
Set—If present and nonzero, then the specified table is set.
Get—If present and nonzero, then the specified table is returned.
Gfsr—If present and nonzero, then the specified GFSR table is being set or retrieved. This keyword is ignored if either the Mt32 or Mt64 keywords are used.
Mt32—Specifies the use of the 32-bit Mersenne Twister generator. If this keyword is used, the
Gfsr keyword is ignored. For an example of this keyword, refer to the
RANDOM_MT32_INIT Procedure.
Mt64—Specifies the use of the 64-bit Mersenne Twister generator. This is only available in 64-bit versions of PV-WAVE. If this keyword is used, the
Gfsr keyword is ignored. For an example of this keyword, refer to the
RANDOM_MT64_INIT Procedure.
Double—If present and nonzero, double precision is used. This keyword is active only when the shuffled table is being set or retrieved.
Discussion
The values in table are initialized by the random number generators. The values are generally all positive. If you wish to reinitialize the array, do one of the following: for MT generators, set the first element of the array to a value greater than 625; for all other generators, set the first element of the array to a nonpositive value. On the next invocation of a routine to generate random numbers, the appropriate table will be reinitialized.
Usually, one should avoid reinitializing these arrays, but it might be necessary sometimes in restarting a simulation. For more details on the shuffled and GFSR generators see the
Introduction.
Example
In this example, three separate simulation streams are used, each with a different form of the generator. Each stream is stopped and restarted. (Although this example is obviously an artificial one, there may be reasons for maintaining separate streams and stopping and restarting them because of the nature of the usage of the random numbers coming from the separate streams.)
nr = 5
iseed1 = 123457
iseed2 = 123457
iseed7 = 123457
; Begin first stream, iopt = 1 (by default)
RANDOMOPT, Set=iseed1
r = RANDOM(nr)
RANDOMOPT, Get=iseed1
PM, r, Title='First stream output'
; PV-WAVE prints the following:
; First stream output
; 0.966220
; 0.260711
; 0.766262
; 0.569337
; 0.844829
PRINT, 'output seed ', iseed1
; PV-WAVE prints: output seed 1814256879
; Begin second stream, iopt = 2
RANDOMOPT, Gen_opt=2
RANDOMOPT, Set=iseed2
r = RANDOM(nr)
RANDOMOPT, Get=iseed2
RANDOM_TABLE, table, /Get
PM, r, Title='Second stream output'
; PV-WAVE prints the following:
; Second stream output
; 0.709518
; 0.186145
; 0.479442
; 0.603839
; 0.379015
PRINT, 'output seed ', iseed2
; PV-WAVE prints: output seed 1965912801
; Begin third stream, iopt = 7
RANDOMOPT, Gen_opt=7
RANDOMOPT, Set=iseed7
r = RANDOM(nr)
RANDOMOPT, Get=iseed7
RANDOM_TABLE, itable, /Get, /Gfsr
PM, r, Title='Third stream output'
; PV-WAVE prints the following:
; Third stream output
; 0.391352
; 0.0262676
; 0.762180
; 0.0280987
; 0.899731
PRINT, 'output seed ', iseed7
; PV-WAVE prints: output seed 1932158269
; Reinitialize seed and resume first stream
RANDOMOPT, Gen_opt=1
RANDOMOPT, Set=iseed1
r = RANDOM(nr)
RANDOMOPT, Get=iseed1
PM, r, Title='First stream output'
; PV-WAVE prints the following:
; First stream output
; 0.0442665
; 0.987184
; 0.601350
; 0.896375
; 0.380854
PRINT, 'output seed ', iseed1
; PV-WAVE prints: output seed 817878095
; Reinitialize seed & table for shuffling & resume second stream
RANDOMOPT, Gen_opt=2
RANDOMOPT, Set=iseed2
RANDOM_TABLE, table, /Set
r = RANDOM(nr)
RANDOMOPT, Get=iseed2
PM, r, Title='Second stream output'
; PV-WAVE prints the following:
; Second stream output
; 0.255690
; 0.478770
; 0.225802
; 0.345467
; 0.581051
PRINT, 'output seed ', iseed2
; PV-WAVE prints: output seed 2108806573
; Reinitialize seed and table for GFSR and resume third stream.
RANDOMOPT, Gen_opt=7
RANDOMOPT, Set=iseed7
RANDOM_TABLE, itable, /Set, /Gfsr
r = RANDOM(nr)
RANDOMOPT, Get=iseed7
PM, r, Title='Third stream output'
; PV-WAVE prints the following:
; Third stream output
; 0.751854
; 0.508370
; 0.906986
; 0.0910035
; 0.691663
PRINT, 'output seed ', iseed7
; PV-WAVE prints: output seed 1485334679