You're scaling your numbers and throwing away the lower part, which _does_
differ from run to run even on VC++. Just print out 'rand()' instead.
It seems that the implementation of the pseudo-random number generator in
the C library shipped with VC++ is rather poor. Try finding a better one
on the Web, it shouldn't be that hard.
Victor
I see what you mean. When i print out just the rand(), the first of
ten calls is very similar each time the program is run, but it _is_
different as you say. It almost makes me want to wrap rand() and
discard the first number each time it is called, but I shouldnt have
to do that.
This is really an odd problem for VC++.
It seems to also affect this wrapper function as well, which is taken
from Koenig's Accelerated C++.
I realize this code can be somewhat costly timewise, but it did
provide a simple function for improving number distribution.
int nrand(int n)
{
if (n <= 0 || n > RAND_MAX)
throw domain_error("Argument to nrand is out of range");
const int bucket_size = RAND_MAX / n;
int r;
do { r = rand() / bucket_size; }
while (r >= n);
return r;
}
I didnt need to look on the Web, Stroustrup's book has one, but until
now, I havent had to use it.
Cheers,
Charles