I'll point out one obvious thing : you should not repeatedly seed the PRNG. It is best to seed it just once. However and this is important : if you want a repeated sequence of random numbers then you have to use the same seed. That gives you the option to use a random sequence or the same sequence again. That can be a very handy thing and I have taken advantage of it in the past.
As Mike mentioned, you use the modulus operator to limit the values. Using a value of 50 with it will give you a range of values between 0 and 49.
A while ago I wrote a function to generate random numbers within an arbitrary, inclusive range. You might find it helpful so here it is :
int GetRandomValue( int minval, int maxval )
{
int range = maxval - minval + 1;
int rv = rand() % range;
return rv + minval;
}
Note the plus one in the range calculation. That's because the range needs to be inclusive. If you want a range of 0 to 50 then you have to use 51 with the modulus operator.
Here's an interesting learning experiment to perform : draw a histogram that show the distribution of values generated by
srand
.