Increase your numbers up by N / RAND_MAX , where N is your desired maximum. If the numbers fit, you can do something like this:
unsigned long long int r = rand() * N / RAND_MAX;
Obviously, if the initial part overflows, you cannot do this, but with N = 250000 you should be fine. RAND_MAX - 32K on many popular platforms.
In general, to get a random number evenly in the interval [A, B] , use:
A + rand() * (B - A) / RAND_MAX;
Of course, you should probably use the appropriate C ++ style <random> library; find this site for many similar questions, explaining how to use it.
Edit: In the hope of preventing the escalation of comments, here is another copy / paste of the correct C ++ solution for a really even distribution over the interval [A, B] :
Remember to leave RNG! If you keep the initial value, you can repeat the same random sequence later.
Kerrek SB
source share