NAG Library Function Document
nag_rngs_basic (g05kac)
1 Purpose
nag_rngs_basic (g05kac) returns a pseudorandom number taken from a uniform distribution between $0$ and $1$.
2 Specification
#include <nag.h> 
#include <nagg05.h> 
double 
nag_rngs_basic (Integer igen,
Integer iseed[])


3 Description
nag_rngs_basic (g05kac) returns the next pseudorandom number from a uniform $\left(0,1\right)$ generator.
The particular generator used to generate random numbers is selected by the value set for the input argument
igen. Consult the
g05 Chapter Introduction for details of the algorithms that can be used.
The current state of the chosen generator is saved in the integer array
iseed which should not be altered between successive calls. Initial states are set or reinitialized by a call to
nag_rngs_init_repeatable (g05kbc) (for a repeatable sequence if computed sequentially) or
nag_rngs_init_nonrepeatable (g05kcc) (for a nonrepeatable sequence).
nag_rngs_uniform (g05lgc) may be used to generate a vector of
$n$ pseudorandom numbers which, if computed sequentially using the same generator, are exactly the same as
$n$ successive values of this function. On many machines
nag_rngs_uniform (g05lgc) is likely to be much faster.
4 References
Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley
5 Arguments
 1:
igen – IntegerInput

On entry: must contain the identification number for the generator to be used to return a pseudorandom number and should remain unchanged following initialization by a prior call to
nag_rngs_init_repeatable (g05kbc) or
nag_rngs_init_nonrepeatable (g05kcc).
 2:
iseed[$4$] – IntegerCommunication Array

On entry: contains values which define the current state of the selected generator.
On exit: contains updated values defining the new state of the selected generator.
6 Error Indicators and Warnings
None.
7 Accuracy
Not applicable.
The generator with the smallest period that can be selected is the basic generator. The period of the basic generator is ${2}^{57}$.
Its performance has been analysed by the Spectral Test, see Section 3.3.4 of
Knuth (1981), yielding the following results in the notation of
Knuth (1981).
$n$ 
${\nu}_{n}$ 
Upper bound for ${\nu}_{n}$ 
$2$ 
$3.44\times {10}^{8}$ 
$4.08\times {10}^{8}$ 
$3$ 
$4.29\times {10}^{5}$ 
$5.88\times {10}^{5}$ 
$4$ 
$1.72\times {10}^{4}$ 
$2.32\times {10}^{4}$ 
$5$ 
$1.92\times {10}^{3}$ 
$3.33\times {10}^{3}$ 
$6$ 
$593$ 
$939$ 
$7$ 
$198$ 
$380$ 
$8$ 
$108$ 
$197$ 
$9$ 
$67$ 
$120$ 
The righthand column gives an upper bound for the values of ${\nu}_{n}$ attainable by any multiplicative congruential generator working modulo ${2}^{59}$.
An informal interpretation of the quantities
${\nu}_{n}$ is that consecutive
$n$tuples are statistically uncorrelated to an accuracy of
$1/{\nu}_{n}$. This is a theoretical result; in practice the degree of randomness is usually much greater than the above figures might support. More details are given in
Knuth (1981), and in the references cited therein.
Note that the achievable accuracy drops rapidly as the number of dimensions increases. This is a property of all multiplicative congruential generators and is the reason why very long periods are needed even for samples of only a few random numbers.
9 Example
This example prints the first five pseudorandom numbers from a uniform distribution between
$0$ and
$1$, generated by nag_rngs_basic (g05kac) after initialization by
nag_rngs_init_repeatable (g05kbc).
9.1 Program Text
Program Text (g05kace.c)
9.2 Program Data
None.
9.3 Program Results
Program Results (g05kace.r)