question about random generator

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.
 
P

Peter Nilsson

There are entropy (et al) devices that generate numbers that are, to
all intents and purposes, truly random. However, they cannot be used to
implement rand() since the sequence generated must be repeatable
(if the programmer sets the same seed as before.)
It may be completely obvious to you, and to many people (including
myself), but it doesn't seem to be obvious to "pete", since he asked.

I think pete's question to Eric was somewhat rhetorical, though perhaps
he too asked on behalf of those not inclined to ask (or know to ask.)
;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top