Tried this, to display rand() before the float roundup:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main (void)
{
srand (time (NULL)); // initialize random seed
// generate a pseudo-random number ranging from 0 to 99
unsigned int r = rand ();
printf("r=%u\n", r);
printf ("%d\n", (int) (100 * (float) r / (RAND_MAX + 1)));
system("pause");
return 0;
}
Some observations:
1) On successive run rand() seems to give *very close values*, so this explains why when you do "(int) (100 * (float) r / (RAND_MAX + 1)))" it gives the same value because the "r" values close to each other (this is a bad!). That explains why botman test does not show this behavior (no roundup).
2) Also time() give time in seconds, so if you run the test in the same second you'll have the same values because the seed is the same. That explains why GetTickCount() works better.
So it seems to make sure rand() doesn't start with close numbers you have to make sure the seeds are not close to each other, so GetTickCount() is a better candidate than time(). Bad rand. 9_9