/* primitive random number generator, yielding numbers from 0 through 2**30-1, mod M the constants were chosen according to Knuth, except for the insertion of CPU_NUM+1; the latter was done in order to avoid having two CPUs get the same return value in a short time window (since there is no lock on RndSeed); users may modify this with such a lock if they wish */ int RndSeed; /* make this GLOBAL */ int Rnd(int M) { RndSeed = (123456789 * (CPU_NUM+1) * RndSeed + 1000000007) % 1073741824; return (RndSeed % M); }