/* random.apb : random number utilities. */ /* Procedure to initialize the seed value. */ randomize() { void srand48(); /* Initialization entry point. */ long now; srand48 (time(&now)); /* Initialize the seed value. */ } /* Function to return a single real value between 0.0 and 1.0. */ double random() { double drand48(); /* Random number generator. */ return (drand48()); } /* Function to return a simulated biased coin toss (true = head). */ boolean flip (probability) double probability; { if (probability == 1.0) return (TRUE); else return ((random() <= probability)); } /* Function to return an integer selected uniformly and pseudorandomly between upper and lower limits. */ int rnd (low, high) int low, high; { double f, drand48(); int i; if (low >= high) i = low; else { f = (drand48() * (high - low + 1) + low); i = (int) floor (f); } return (i); }