// pseudoRandom.C // // Written 11 Feb 96 by Max Hailperin // // Procedure for uniformly pseudorandomly choosing among options. // // Warning: the simple implementation below only works on systems where the // procedure "random" produces good low-order bits. On systems derived from earlier // versions of the Berkeley source code, if you called pseudoRandom(2) repeatedly, // for example, you would get 0 and 1 in strict alternation. On such a system, // a more complex implementation would need to be used here to compensate. #include "pseudoRandom.h" extern "C" long random(); // this declares a commonly (though not universally) // available C library routine I am *assuming* // in fact is available unsigned pseudoRandom(unsigned choices) // returns a result in range from 0 // up to but not including choices { return random()%choices; }