K
Keith Thompson
Eric Sosman said:pete wrote: [...]Does "pseudo-random" mean the same thing as "uniformly distributed" ?
No. The Standard doesn't actually guarantee any particular
distribution from rand(). On the DeathStation 9000, rand()
returns 42 every time you call it.
I've always assumed that the Standard doesn't describe the
distribution because doing so would require a lot of fairly
deep mathematics; Knuth devotes thirty-five pages to the topic
"What is a random sequence?" Developing a useful theory of
the randomness of finite sequences is (it seems) no simple
matter -- certainly not a topic for the Standard to explicate.
So the Standard just says "pseudo-random," and we all understand
that it means "sort of uniform-ish in a sort of hand-waving way,
noodge noodge wink wink."
Anyhow, that's how I've imagined the committee's intent.
The Rationale sheds no further light on the matter, either.
The Standard says that rand() "computes a sequence of pseudo-random
integers in the range 0 to RAND_MAX". Though it doesn't explicitly
say how they're distributed, I don't think anything other than a
uniform distribution would make any sense. If a normal distribution
were intended, integers in the range 0 to RAND_MAX would be an odd way
to specify it.
Also, the sample implementation yields a more or less uniform
distribution.
It's debatable (but *not* usefully debatable!) whether the DS9K's
implementation of rand() is conforming. It would have been nice,
IMHO, to have a footnote that mentions a uniform distribution, however
handwavingly.