Let’s say you need a random number from 0 to 2 (0, 1 or 2). If you do this:
int n = 3;
x = rand() % n;
your code is broken, thanks to modulo bias. You will always get modulo bias whenever RAND_MAX + 1 of your rand() function is not evenly divisible by your modulus n.
Shinobu goes on to explain the details and offers an alternative approach.