The routines for creating pseudo-random numbers in this library all have a period of 2 and 6–7 digits accuracy. They are based upon code by Ahrens, Dieter, & Grube. They use a multiplicative congruential generator which is certainly not the state of the art and may not be suitable for critical or sophisticated use.
The routines are:
Before any random numbers can be selected, a seed must be set using PDA_RNSED. The integer seed should satisfy the relationship
where is a non-negative integer. A fixed seed gives rise to a reproducible sequence of pseudo-random numbers.
For a non-repeatable sequence, there is no equivalent to NAG routine G05CCF because the system clock used to create the seed is not accessible portably in Fortran, and PDA is independent of other libraries. However, the following code has the desired effect.
PSX_TIME returns the time in units of clock ticks since some arbitrary time. See SUN/121 for more details and linking instructions. The above code also permits storage of the chosen seed.
There is a major difference between the PDA random-number routines and those provided in the standard NAG library: in general the former are single-precision functions, whereas the latter are double precision. However, PDA_RNPOI and the corresponding G05DRF are both integer functions.
Like G05CAF, PDA_RAND has a dummy argument demanded by the Fortran standard. It is convenient to set it to zero. Here is an example where two random numbers are drawn from a uniform distribution between 0 and 1. In this example a fixed seed is used, but you could use the computer’s clock to create a random seed (see Section 17.1).
The EXTERNAL statement is recommended, although in many cases it will be unnecessary. To obtain in the range [,] as provided by G05DAF, merely apply the following relationship.
PDA_RNEXP is only a partial replacement for G05DBF in that it computes pseudo-random numbers from , whereas G05DBF uses the function . Thus its argument is also a dummy mandated by the Fortran standard.
The following code shows the remaining three routines in action.
Apart from the change of data type, calls to G05DDF can be replaced with PDA_RNNOR using the same arguments. PDA_RNPOI is in effect a renamed G05DRF.
PDA_RNGAM only has one argument—the mean—of the Gamma function, whereas G05FFF has a second scaling parameter similar in role to the argument of G05DBF. G05FFF also generates a vector of pseudo-random numbers.