Discussion: Random Numbers
Afficher un message
Vieux 16/01/2008, 13h16   #1
Ioannis Vranos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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?
  Réponse avec citation
 
Page generated in 0,04250 seconds with 9 queries