1File: rand.c Page 1 1 /* rand.c - kluges a random number generator with addition & overflow */ 2 #include 3 4 5 #define NSEEDS 7 6 7 MLOCAL UWORD _seeds[NSEEDS] = 8 { 0, 24213, 12345, 4622, 2143, 32010, 7942 }; 9 10 MLOCAL WORD _seedptr=0; 11 12 13 WORD srand(seed1) 14 int seed1; 15 { 16 WORD ncs; 17 _seeds[0] = seed1; 18 for( ncs = seed1&077; ncs; ncs-- ) 19 rand(); 20 return(rand()); 21 } 22 23 24 WORD rand() 25 { 26 UWORD tot, ii; 27 28 for( tot=0, ii=0; ii= NSEEDS ) 31 _seedptr = 0; 32 _seeds[_seedptr] = tot; 33 return( tot >> 1 ); /* ignore lo bit because of addition */ 34 } 35