nag_random_continuous_uniform (g05cac) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_random_continuous_uniform (g05cac)

## 1  Purpose

nag_random_continuous_uniform (g05cac) returns a pseudorandom number taken from a uniform distribution between 0 and 1.

## 2  Specification

 #include #include
 double nag_random_continuous_uniform ()

## 3  Description

nag_random_continuous_uniform (g05cac) returns the next pseudorandom number from the basic uniform (0,1) generator.
The basic generator uses a multiplicative congruential algorithm
The integer ${b}_{i+1}$ is divided by ${2}^{59}$ to yield a real value $y$, which is guaranteed to satisfy
 $0 < y < 1 .$
The value of ${b}_{i}$ is saved internally in the code. The initial value ${b}_{0}$ is set by default to $123456789×\left({2}^{32}+1\right)$, but the sequence may be re-initialized by a call to nag_random_init_repeatable (g05cbc) for a repeatable sequence, or nag_random_init_nonrepeatable (g05ccc) for a non-repeatable sequence.

## 4  References

Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley

None.

None.

Not applicable.

## 8  Further Comments

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.
 $n$ ${\nu }_{n}$ Upper bound for ${\nu }_{n}$ $2$ $3.44×{10}^{8}$ $4.08×{10}^{8}$ $3$ $4.29×{10}^{5}$ $5.88×{10}^{5}$ $4$ $1.72×{10}^{4}$ $2.32×{10}^{4}$ $5$ $1.92×{10}^{3}$ $3.33×{10}^{3}$ $6$ $593$ $939$ $7$ $198$ $380$ $8$ $108$ $197$ $9$ $67$ $120$
The right-hand 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 statistical independence 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

The example program prints the first five pseudorandom numbers from a uniform distribution between 0 and 1, generated by nag_random_continuous_uniform (g05cac) after initialization by nag_random_init_repeatable (g05cbc).

### 9.1  Program Text

Program Text (g05cace.c)

None.

### 9.3  Program Results

Program Results (g05cace.r)

nag_random_continuous_uniform (g05cac) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual