RandomInt.mesa
Produces a random sequence of INTEGERs. For complete documentation see Random.mesa.
Last edited by:
MBrown on August 27, 1982 2:12 pm
RandomInt: CEDAR DEFINITIONS = BEGIN
Init: PROC [range: INTEGER ← 0, seed: INTEGER ← 0] RETURNS [trueSeed: INTEGER];
The parameters range and seed determine the sequence generated by procedure Next (also Choose) below. If range<=0, Next will produce results in [0..LAST[INTEGER]]; otherwise, Next will produce results in [0..range). If seed=0, a default seed value is used to determine the starting point of the sequence; if seed>0, seed is scaled if necessary and then used; if seed<0, a seed value is derived from the system clock. In any case, the seed value actually used (after scaling) is the INTEGER value returned by Init.
Avoid small values of the range parameter; the intent of range is to allow the same sequence to be produced by different machines.
Next: PROC [] RETURNS [INTEGER];
A call to Next returns the next term in the sequence determined by the most recent call to Init.
Choose: PROC [min, max: INTEGER] RETURNS [INTEGER--[min..max]--];
! Error [badInterval] ([min..max] is an illegal interval).
Chooses a point in the interval [min..max] at random. (The choice is quite random, even if this interval is large.) If the interval is empty (min > max), raises ERROR Error[badInterval].
Error: ERROR [ec: ErrorType];
ErrorType: TYPE = { badInterval };
END.