Random Numbers

Here we only consider modulo generators with b = 0. Such generators are called multiplicative and the short form MLCG(a,M) is used for such generators. These are the most commonly used, since one can show that additive generators, i.e. generators with b in general non zero have undesirable statistical properties.

The choices for the parameter a are manifold. For example a=16807, 630360016 or 397204094 are possible choices with M = 231-1. There are particular bad choices for the multiplier a. For example a = 65539is such a bad choice. The decision whether a particular value for a is a good or bad choice with respect to the statistical properties can be made based on theorems that limit the possible choices for a. Also some statistical tests exclude values for a. Here we do not have space to go into these details and the interested reader is directed to the literature.

The following program excerpt is part of the program random. With this program three types random number generators can be called and tested.  

Program Modulo Generator

The modulo generator is written such that the integer numbers are converted to real numbers. This allows that very combination of modulus (modul), multiplier (multi) and increment (inc) can be tested within the limits set by the underlying hardware. The generator must be initialized with a seed (seed). The generator generates max_sweep numbers and returns them in the array x as normalized numbers in the interval (0,1).

The following parameters are suggested upon first usage

  • modul = 2147483647
  • multi = 16807
  • inc = 0
  • seed = 4711

/*-------------------------------------------------------------------------- */

/* Modulo Generator */

/*-------------------------------------------------------------------------- */

int ModGenerator(modul,multi,inc,seed,max_sweeps,x)

int modul;

int multi;

int inc;

int seed;

int max_sweeps;

float *x;

{

/*---------------------------------------------------------- */

/* Declarations */

/*---------------------------------------------------------- */

int i;

double r;

double factor, increment, modulus;

/*---------------------------------------------------------- */

/* End of declares */

/*---------------------------------------------------------- */

r = (double) seed;

factor = (double) multi;

increment = (double) inc;

modulus = (double) modul;

for(i=0; i< max_sweeps; i++) {

r=fmod(r*factor + increment,modulus);

x[i] = (float) r / modulus;

}

return 0;

}

previous page next page