nag_rngs_basic (g05kac) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

NAG Library Function Document

nag_rngs_basic (g05kac)

+ Contents

    1  Purpose
    7  Accuracy

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 0,1 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 re-initialized by a call to nag_rngs_init_repeatable (g05kbc) (for a repeatable sequence if computed sequentially) or nag_rngs_init_nonrepeatable (g05kcc) (for a non-repeatable 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:     igenIntegerInput
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.

8  Further Comments

The generator with the smallest period that can be selected is the basic generator. The period of the basic generator is 257.
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 νn Upper bound for νn
2 3.44×108 4.08×108
3 4.29×105 5.88×105
4 1.72×104 2.32×104
5 1.92×103 3.33×103
6 593 939
7 198 380
8 108 197
9 67 120
The right-hand column gives an upper bound for the values of νn attainable by any multiplicative congruential generator working modulo 259.
An informal interpretation of the quantities νn is that consecutive n-tuples are statistically uncorrelated to an accuracy of 1/ν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)


nag_rngs_basic (g05kac) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012