extern "C" { #include "stdlib.h"}void randomSeed(unsigned int seed){ if (seed != 0) { srandom(seed); }}long random(long howbig){ if (howbig == 0) { return 0; } return random() % howbig;}long random(long howsmall, long howbig){ if (howsmall >= howbig) { return howsmall; } long diff = howbig - howsmall; return random(diff) + howsmall;}

//generates a psuedo-random integer between 0 and max int randint(int max) { return int(max*rand()/(RAND_MAX+1.0)); } //generates a psuedo-random integer between min and max int randint(int min, int max) { if (min>max) { return max+int((min-max+1)*rand()/(RAND_MAX+1.0)); } else { return min+int((max-min+1)*rand()/(RAND_MAX+1.0)); } }