Hello,
I made a program that uses a random number generator,
my generator looks like this:
void randomize ()
{
srand((unsigned)time(NULL));
}
int random (int highest)
{
int randomnum;
randomnum= int(highest*rand()/(RAND_MAX+1.0));
return randomnum;
}
here is the piece of code that calls the generator:
int first,second;
randomize();
first=random(8);
second=random(11);
the weird thing is that the second call works well and gives a random number every time,but the first doesn't.
It gives the same number every time,and that number always equals
the function parameter(int highest) minus 1(when the parameter is 8
the function returns 7,when I changed it to 10 the function returned 9 etc.).
Can anyone explain why does it happen?
p.s.
I'm using VC++ 6.0