The routine may be called by the names g05kgf or nagf_rand_init_nonrepeat.
g05kgf selects a base generator through the input value of the arguments genid and subid, and then initializes it based on the values taken from the real-time clock, resulting in the same base generator yielding different sequences of random numbers each time the calling program is run. It should be noted that there is no guarantee of statistical properties between sequences, only within sequences.
A definition of some of the terms used in this description, along with details of the various base generators can be found in the G05 Chapter Introduction.
L'Ecuyer P and Simard R (2002) TestU01: a software library in ANSI C for empirical testing of random number generators Departement d'Informatique et de Recherche Operationnelle, Universite de Montreal https://www.iro.umontreal.ca/~lecuyer
Maclaren N M (1989) The generation of multiple independent sequences of pseudorandom numbers Appl. Statist.38 351–359
Matsumoto M and Nishimura T (1998) Mersenne twister: a 623-dimensionally equidistributed uniform pseudorandom number generator ACM Transactions on Modelling and Computer Simulations
Wichmann B A and Hill I D (2006) Generating good pseudo-random numbers Computational Statistics and Data Analysis51 1614–1622
Wikramaratna R S (1989) ACORN - a new method for generating sequences of uniformly distributed pseudo-random numbers Journal of Computational Physics83 16–31
1: – IntegerInput
On entry: must contain the type of base generator to use.
On entry: if , subid indicates which of the sub-generators to use. In this case, the sub-generator is used.
If , subid indicates the values of and to use, where is the order of the generator, and controls the size of the modulus, , with . If , the default values of and are used, otherwise values for and are calculated from the formula, .
If and the range of the generator is set to , otherwise the range is set to ; in this case the sequence is identical to the implementation of MRG32k3a in TestU01 (see L'Ecuyer and Simard (2002)) for identical seeds.
For all other values of genid, subid is not referenced.
3: – Integer arrayCommunication Array
On exit: contains information on the selected base generator and its current state.
4: – IntegerInput/Output
On entry: the dimension of the state array, or a value . If the Mersenne Twister () is being used and the skip ahead routine g05kjforg05kkf will be called subsequently, then you must ensure that .
On exit: if on entry, then the required length of the state array for the chosen base generator, otherwise lstate is unchanged. When (Mersenne Twister) a value of is returned, allowing for the skip ahead routine to be subsequently called. In all other cases the minimum length, as documented in the constraints below, is returned.
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or is used it is essential to test the value of ifail on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
On entry, .
Constraint: , , , , or .
On entry, .
Constraint: or .
Required length of state array returned in lstate but state array not initialized.
An unexpected error has been triggered by this routine. Please
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
8Parallelism and Performance
g05kgf is not threaded in any implementation.
In order to preserve the statistical properties of the base generators, g05kgf should only be called once. If multiple streams of values are required then one of the methods described in Section 2.1.1 in the G05 Chapter Introduction should be used.
However, for illustrative purposes only, this example calls g05kgf twice. At each call a sample of values from a discrete uniform distribution are generated and then the two samples are compared.