|
|
1.1 ! root 1: /* ! 2: * Random number generator, of period 2 ^ 32. Returns random numbers (ints) in ! 3: * the interval [0, 2^15-1]. ! 4: * The algorithm used is a linear congruential method, where the internal ! 5: * computation is done in unsigned longs (mod 2^32). The numbers from ! 6: * this sequence are right shifted 17 bits so that the most random 15 ! 7: * bits are returned. ! 8: * All this is from Knuth Vol 2, 2nd ed., ch 3. The choice of multiplier ! 9: * is made from the table in 3.3.4.E, pp102. ! 10: */ ! 11: ! 12: #define A 1664525L /* Multiplicative generator */ ! 13: #define C 907633387L /* Additive generator */ ! 14: ! 15: ! 16: static long seed = 1; ! 17: ! 18: srand(n) ! 19: unsigned int n; ! 20: { ! 21: seed = n; ! 22: } ! 23: ! 24: rand() ! 25: { ! 26: seed = seed * A + C; ! 27: return ((seed >> 17) & 077777); ! 28: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.