Random Numbers ...

Doug Gwyn gwyn at brl-smoke.ARPA
Sun Feb 28 11:11:20 AEST 1988


In article <3472 at bobkat.UUCP> m5 at bobkat.UUCP (Mike McNally (Man from Mars)) writes:
>Linear congruential random number generators are fine because of their
>simplicity, but unless the entire seed is used the results are not very
>random.  Get ahold of a graphics system and do a simple pairs test by
>plotting random x-y positions for a while.  You'll see nifty patterns.

There are patterns in the sequences produced by any deterministic
generator, although you may not be able to see them via simple plotting.
This is what makes cryptanalysis of machine ciphers feasible.

>The BSD (?) random() functions are decidedly superior, though somewhat
>slower.

Those use a linear-feedback shift-register method (if used in a mode
where the state information is greater than 32 bits).  Golomb wrote a
whole book about the algebra and statistics of such sequences.  LFSR
sequences can act as if they are "more random" than LC sequences for
naive use, but it does depend on what you use them for.

UNIX System V provides 48-bit LC sequence generators under names such
as irand48(), drand48(), etc.  Because these use more bits than the
example code I posted, they are generally better.  It is too bad that
there doesn't seem to be a single, FAST, statistically dominant method
that could be provided for all applications.  Programmers keep having
to provide their own RNGs to have sufficient confidence in their
suitability for specific applications.



More information about the Comp.lang.c mailing list