1 static long rntb[32] = {
2 3, 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342,
3 0xde3b81e0, 0xdf0a6fb5, 0xf103bc02, 0x48f340fb, 0x7449e56b,
4 0xbeb1dbb0, 0xab5c5918, 0x946554fd, 0x8c2e680f, 0xeb3d799f,
5 0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88, 0xe369735d,
6 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc,
7 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e,
8 0x8999220b, 0x27fb47b9
9 };
10
11 static long *fptr = &rntb[4];
12 static long *rptr = &rntb[1];
13 static long *state = &rntb[1];
14 static int rand_type = 3;
15 static int rand_deg = 31;
16 static int rand_sep = 3;
17 static long *end_ptr = &rntb[32];
18
srrandom(x)19 srrandom(x)
20 int x;
21 {
22 register int i;
23 long rrandom();
24
25 state[0] = (long) x;
26 if (rand_type != 0) {
27 for (i = 1; i < rand_deg; i++) {
28 state[i] = 1103515245L * state[i - 1] + 12345;
29 }
30 fptr = &state[rand_sep];
31 rptr = &state[0];
32 for (i = 0; i < 10*rand_deg; i++) {
33 (void) rrandom();
34 }
35 }
36 }
37
38 long
rrandom()39 rrandom()
40 {
41 long i;
42
43 if (rand_type == 0) {
44 i = state[0] = (state[0]*1103515245L + 12345) & 0x7fffffffL;
45 } else {
46 *fptr += *rptr;
47 i = (*fptr >> 1) & 0x7fffffffL;
48 if (++fptr >= end_ptr) {
49 fptr = state;
50 ++rptr;
51 } else {
52 if (++rptr >= end_ptr) {
53 rptr = state;
54 }
55 }
56 }
57 return(i);
58 }
59
get_rand(x,y)60 get_rand(x, y)
61 register int x, y;
62 {
63 register int r, t;
64 long lr;
65
66 if (x > y) {
67 t = y;
68 y = x;
69 x = t;
70 }
71 lr = rrandom();
72 lr &= (long) 0x00007fff;
73 r = (int) lr;
74 r = (r % ((y - x) + 1)) + x;
75 return(r);
76 }
77
rand_percent(percentage)78 rand_percent(percentage)
79 register int percentage;
80 {
81 return(get_rand(1, 100) <= percentage);
82 }
83
coin_toss()84 coin_toss()
85 {
86
87 return(((rrandom() & 01) ? 1 : 0));
88 }
89