It appears that your immediate problem has been dealt with, but I think it's still worth mentioning one more point. Using the remainder to clamp outputs from rand to a specified range will usually cause bias in the results. To be specific, if the range of the generator (RAND_MAX in the case of C or C++) isn't a multiple of the range you're clamping to, some outputs will occur more often than others. For comparison, consider trying to divide 11 candies evenly between 3 children (without breaking any into pieces). The only way you can do it is NOT hand out some of the candy. Likewise, with a random number generator, the only way to get an even distribution in your output is not use some of the inputs.
int rand_lim(int limit) {
/* return a random number between 0 and limit inclusive.
*/
int divisor = RAND_MAX/(limit+1);
int retval;
do {
retval = rand() / divisor;
} while (retval > limit);
return retval;
}
As asveikau pointed out in his post, you generally want to use the upper bits from a typical linear congruential generator. The lower bits are generally more predictable. By dividing instead of taking a remainder, this retains upper bits. Though this does have a while loop, it often executes only once, and rarely more than twice, so its impact on performance is pretty minimal.
Whether this is worthwhile depends on the use you're making of the numbers you generate -- if you want dice or cards for a game that your kids will play a couple of times, using a remainder generally won't hurt a thing. If you're trying to do some sort of Monte Carlo simulation (for example) you probably want to be a bit more careful though...