Here's a general procedure for producing a random number in a specified range:
int randInRange(int min, int max)
{
return min + (int) (rand() / (double) (RAND_MAX + 1) * (max - min + 1));
}
Depending on the PRNG algorithm being used, the %
operator may result in a very non-random sequence of numbers.