Modula-2 || Compiler & Tools || Library || Search Engine


Ulm's Modula-2 Library:
RandomGenerator


NAME

RandomGenerator - pseudo random number generator

SYNOPSIS

PROCEDURE IntVal() : INTEGER;
PROCEDURE RealVal() : REAL;
PROCEDURE Random(low, high: INTEGER) : INTEGER;
PROCEDURE Flip() : BOOLEAN;
PROCEDURE Init(seed: INTEGER);

DESCRIPTION

RandomGenerator implements the subtractive method taken from Knuth, Seminumerical Algorithms, 3.2.2 and 3.6. This pseudo random number generator is recommended if a large quantity of uniformly distributed random numbers is needed. The produced random numbers are not cryptographically secure.

IntVal, RealVal, Random and Flip return uniformely distributed values for the requested type and value range:
IntVal 32-bit integer
RealVal floating point number out of [0..1)
Random integer out of [low..high]
Flip TRUE or FALSE

By default, RandomGenerator takes a seed value that is derived from the current time and the process id. Init allows to override this default. This may be useful to replay sequences of pseudo random numbers or to use better sources for seed values.

BUGS

Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin. -- John von Neumann (1951)
Edited by: borchert, last change: 2003/12/10, revision: 1.5, converted to HTML: 2003/12/10

Modula-2 || Compiler & Tools || Library || Search Engine