I am working on a C++ assignment for my class, and we have to use rand () with a seed of 99 to produce a set of values. However, my problem is that when I try to create a value within our parameters, the number is different than what the instructor provided us for a definite first number. The code is shown below:
int lottoNumber;
srand (RANDOM_NUMBER_SEED);
do
{
lottoNumber = rand ();
} while (lottoNumber > 25 || lottoNumber < 1);
cout << lottoNumber << endl;
The value produced from this is 13, while the number expected to be produced is 2. Any help as to why this is different would be great, thanks!
lottoNumber = rand() % 25 + 1;
. It may not be perfectly distributed but it should do for anything other than a real lottery but if it were a real lottery, I suspect government regulations would require something better than a PRNG :-) – Remmer