1 /*************************************************************************/
3 /* Copyright (c) 1994 Stanford University */
5 /* All rights reserved. */
7 /* Permission is given to use, copy, and modify this software for any */
8 /* non-commercial purpose as long as this copyright notice is not */
9 /* removed. All other uses, including redistribution in whole or in */
10 /* part, are forbidden without prior written permission. */
12 /* This software is provided with absolutely no warranty and no */
15 /*************************************************************************/
21 #define MULT 1103515245
23 #define MASK (0x7FFFFFFF)
24 #define TWOTO31 2147483648.0
29 local int lastrand; /* the last random number */
32 * XRAND: generate floating-point random number.
38 double xl, xh; /* lower, upper bounds on number */
43 return (xl + (xh - xl) * prand());
46 void pranset(int seed)
52 randx = (A*seed+B) & MASK;
53 A = (MULT * A) & MASK;
54 B = (MULT*B + ADD) & MASK;
60 Return a random double in [0, 1.0)
64 randx = (A*randx+B) & MASK;
65 return((double)lastrand/TWOTO31);
69 * CPUTIME: compute CPU time in min.
72 #include <sys/types.h>
73 #include <sys/times.h>
80 if (times(&buffer) == -1)
81 error("times() call failed\n");
82 return (buffer.tms_utime / (60.0 * HZ));
86 * ERROR: scream and die quickly.
89 error(msg, a1, a2, a3, a4)
90 char *msg, *a1, *a2, *a3, *a4;
94 fprintf(stderr, msg, a1, a2, a3, a4);