Random Numbers
I am reading TC++PL3 and on page 685 it is written:
"Producing a good random-number generator isn't easy, and unfortunately
not all systems deliver a good rand(). In particular, the low-order bits
of a random number are often suspect, so rand() %n is not a good
portable way of generating a random number between 0 and n-1. Often,
int((double(rand())/RAND_MAX) *n) gives acceptable results. However, to
seriously use that formula, we must take care of the minuscule
probability that the result will be n".
Q1: What are the "low-order bits"?
Q2: "we must take care of the minuscule probability that the result will
be n". This means the result of rand() call, or the result of the
formula? And why?
|