DEFINITION MODULE random;
(*
    Title: 	Pseudo-Random Numbers from a Fibonacci series
    LastEdit:	"Fri Nov 18 19:15:51 1983"
    Author: 	jd
		Cambridge University Computer Laboratory
*)

(* Generates pseudo-random CARDINALS. RandomCard returns a random 
    CARDINAL with a uniform distribution.
    ZeroTo and OneTo return CARDINALS uniformly distributed  from 
    0 and 1 respectively to their upper bound argument. Uniform
    returns a random CARDINAL lwb <= c <= upb.

    NB. if the interval width of any of ZeroTo, OneTo and Uniform 
    is a power of 2, the result will be highly non-random!
*)


EXPORT QUALIFIED Seed, RandomCard, ZeroTo, OneTo, Uniform;

PROCEDURE Seed (c: CARDINAL);
    (* define a seed. Since there are two seeds, calling this procedure
       twice will set both of them.
    *)
PROCEDURE RandomCard (): CARDINAL;
    (* a random cardinal which is the sum of the two current seeds *)
PROCEDURE ZeroTo (upb: CARDINAL): CARDINAL;
    (* 0 <= r <= upb *)
PROCEDURE OneTo (upb: CARDINAL): CARDINAL;
    (* 1 <= r <= upb *)
PROCEDURE Uniform (lwb, upb: CARDINAL): CARDINAL;
    (* lwb <= r <= upb *)

END random.
