RandomCard.mesa
Produces a random sequence of CARDINALs. For complete documentation see Random.mesa.
Last edited by:
MBrown on August 27, 1982 2:13 pm
RandomCard: CEDAR DEFINITIONS = BEGIN
Init: PROC [seed: INTEGER ← 0] RETURNS [trueSeed: INTEGER];
The parameter seed determines the sequence generated by procedure Next (also Choose) below. 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.
Next: PROC [] RETURNS [CARDINAL];
A call to Next returns the next term in the sequence determined by the most recent call to Init.
Choose: PROC [min, max: CARDINAL] RETURNS [CARDINAL--[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.