1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <time.h>
4 
5 #ifndef __MWERKS__
irand()6 irand()	/* initialize random number generator */
7 {
8   time_t tv;
9 
10   tv = (time(NULL)&255);
11 
12   srand(tv);
13 }
14 #else
irand(n)15 irand(n)	/* initialize random number generator */
16 	int n;
17 {
18 	srand((unsigned int)clock());
19 	}
20 #endif
21 
nrand(n)22 nrand(n)	/* returns a random number between 1 and n where n < 64K) */
23 	int n;
24 {
25 	int rand();
26 	long rn;
27 
28 	rn = rand();
29 #ifdef RAND32
30 	rn = rn >> 16;
31 #endif
32 	rn = rn * n;
33 	rn = rn >> 15;
34 	return (int)rn;
35 	}
36 
37