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

NAG Library Function Document

nag_random_continuous_uniform (g05cac)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

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

2  Specification

#include <nag.h>
#include <nagg05.h>
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
b i+1 = 13 13 × b i  mod  2 59 .
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 × 2 32 + 1 , 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

5  Arguments

None.

6  Error Indicators and Warnings

None.

7  Accuracy

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 ν n Upper bound for ν 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 ν n  attainable by any multiplicative congruential generator working modulo 2 59 .
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 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)

9.2  Program Data

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

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