A Random.T (or just a generator) is a pseudo-random number generator. pseudo-random number
INTERFACE Random;
TYPE
T = OBJECT METHODS
integer(min := FIRST(INTEGER);
max := LAST(INTEGER)): INTEGER;
real(min := 0.0e+0; max := 1.0e+0): REAL;
longreal(min := 0.0d+0; max := 1.0d+0): LONGREAL;
extended(min := 0.0x+0; max := 1.0x+0): EXTENDED;
boolean(): BOOLEAN
END;
Default <: T OBJECT METHODS
init(fixed := FALSE): Default
END;
END Random.
Individual generators are unmonitored, and all the operations have side effects.
The methods provided by a generator rand are:
The call rand.integer(a, b) returns a uniformly distributed INTEGER in the closed interval [a..b].
The call rand.real(a, b) returns a uniformly distributed REAL in the half-open interval [a..b).
The call longreal and extended are like real, but return values of the specified types.
The call rand.boolean() returns a random BOOLEAN value.
It is a checked runtime error if min > max on any call.
NEW(Default).init() creates and initializes a generator (see below for implementation details). If fixed is TRUE, a predetermined sequence is used. If fixed is FALSE, init chooses a random seed in such a way that different sequences result even if init is called many times in close proximity.
WITH rand = NEW(Random.Default).init() DO
FOR i := FIRST(a) TO LAST(a) - 1 DO
WITH j = rand.integer(i, LAST(a)) DO
Exchange "a[i]" and "a[j]"
END
END
END