Using the NAG Toolbox for MATLAB - Part 3 - The G05 chapter - Random Number Generators

The G05 chapter - Random Number Generators

The reliable generation of a sequence of random numbers is a task that is found in many areas of computation - for example, in Monte Carlo simulation. The G05 chapter contains numerous routines for doing this; we illustrate the use of two of them here.

A fundamental distinction in this area is the one between pseudo and quasi random numbers. The former are numbers whose statistical properties are as close as possible to those of "true" random numbers - i.e. those obtained from an intrinsically random physical process (such as the time elapsed between clicks of a Geiger counter placed next to a radioactive sample). For example, consecutive numbers in a pseudo-random sequence have negligible correlation between them. Quasi-random numbers, by contrast, do not have this property - instead, they are designed to give a more even distribution in space; this property makes them well-suited for Monte Carlo methods where, for a given sequence length, they yield more accurate estimates than pseudo-random numbers.

Our example should make this distinction clear. Here is the code for the generation of two pseudo-random sequences of numbers, using the g05fa routine:

   
% The number of (x,y) pairs to generate.
n = int32(10000);

% Specify the mechanism for generating pseudo-random numbers.
g05za('O');

% Now generate two vectors of n of them, in the interval [a,b].
a = 0;
b = 1;
[x] = g05fa(a, b, n);
[y] = g05fa(a, b, n);

And this is the code for generating a quasi-random 2D sequence, via g05yd, which uses the so-called Faure method:

   
% The generator creates generate vectors of random numbers; 
% first, specify the length of each vector.
idim = int32(2);

% Initialize the Faure quasi-random number generator.
[iref, ifail] = g05yc(idim);

% Now generate n 2D vectors of them.
[quasi, irefOut, ifail] = g05yd(n, iref);

If each sequence is interpreted as a collection of points in 2D space, it can be displayed as a scatter plot (see Figure 4), which clearly shows the difference between the two types of generator. Though they both appear to fill the 2D space randomly, the quasi-random sequence fills it in a more uniform fashion (technically, this is because each number in the sequence is designed to be maximally avoiding of the others).


Figure 4: Two types of random number generation.

The MATLAB script for this demo is available as the file NAGToolboxDemos/Random_number_generation/g05fa_demo.m, distributed in this archive.