quote:
Original post by Kern Carrot : if RAND_MAX == 10 and you call rand() % 3 the probability would be : 0=4 1=3 2=3. In the long run this makes for a big mistake and since that mistake is alway in the low number it imbalance things.
There honestly should be a FAQ for this random stuff. It's asked every month here and every month there are ppl saying "use rand()%x" and other ppl correcting them. * S I G H *
Although in a game, I don't think a slightly biased distribution is noticeable.
in my text book, this is how they say you get a random int: // place this at top of int_main void rand_seed() { int seed = static_cast<int>(time(0)); srand(seed); }
// gives you random int in the range you specify int rand_int(int bottom_range, int top_range) { return bottom_range + rand() % (top_range - bottom_range + 1); }