[comp.lang.pascal] help on random number generator & t

mead@uxh.cso.uiuc.edu (07/24/90)

Actually, I believe Philip Munts helped me out before and appeared
sharp while doing it, but ...

I tested the random number generators in Press et al s' (sp?)
_Numerical Recipes_ against the TP5.5 function RANDOM (with the
RANDOMIZE function's seed, whatever that is - a longint I guess) using
the "empirical derivation of Pi" test program with favorable results.
Well, actually, both where only good.  Neither reproduced Pi to more
than a digit or two :(  I think I looked at a couple of other (self
invented) tests and turned out fine.

'Course, just because Press et al think they're godlike doesn't mean we
all have to get nose bleeds bowing to them :) - maybe their generator
isn't so hot.  I'd prefer running statistical tests on samples of a few
100K numbers before I bet my life on them.

Actually, that's a question I've thought about - "What test are there
to determine the soundness of a random number generator?" - our lab
cranks monty carlo simulations out all the time and my advisor is of
the opinion that "The generators have been out there long enough that
all the bugs have been worked out.  Yeah, the general problem has been
solved."

-alan mead : mead@uxh.cso.uiuc.edu

north@manta.NOSC.MIL (Mark H. North) (07/25/90)

In the first place I wouldn't trust Press, et al since I found them to be
quite confused concerning deconvolution -- perhaps they are not so confused
in other areas, I don't know.

Secondly, I wouldn't trust any canned 'random number generator' without
testing. They usually aren't documented very well so you don't know what
you are getting. And even if you are told what kind of RNG is being used
you don't know if it is being implemented properly. For example, the
multiplicative congruential RNG is one of the best (I have found) but its
performance is dependent on the seed chosen. If the seed is even you can
end up with very short sequences before repeat (as small as 2). There are
other restrictions depending on the generator. The way some implementers
deal with this is by resorting to jiggery-pokery with your seed to force it
to conform to requirements. Unfortunately, by this we have lost all control
of the situation.

There are a number of tests used for RNGs such as the poker test, the run
test, etc. However, the ultimate test for a RNG is in YOUR application.
There is no substitute for sanity checks on what you are getting in your
application. Unfortunately, when a RNG fails to perform in one's particular
use the failure can be quite subtle, so beware. Anyone who blindly uses a
RNG for a serious application is either ignorant or a fool. The best advice
I can give is read and understand Knuth and the references he gives and then
proceed with caution.

Mark

ftpam1@acad3.fai.alaska.edu (MUNTS PHILLIP A) (07/25/90)

In article <1157@manta.NOSC.MIL>, north@manta.NOSC.MIL (Mark H. North) writes...
> 
> 
> 
>In the first place I wouldn't trust Press, et al since I found them to be
>quite confused concerning deconvolution -- perhaps they are not so confused
>in other areas, I don't know.
> 
>Secondly, I wouldn't trust any canned 'random number generator' without
>testing. They usually aren't documented very well so you don't know what

     According to whoever wrote the article I referenced in the October 1988
"Communications of the ACM" (I only copied the pages with program listings),
testing should be for correctness rather than randomness.  In other words,
they claim the algorithm is provably random and all you need to do is make
sure the implementation is correct.  All I can say is that it works for me.
The article specifically mentions Turbo 3.0 so Borland may have indeed done 
better in 5.5.

     Again, the myths and legends concering seeds arises from overflow in
the internal calculations, which are averted in the unit I posted before.
The author(s) give a test program fragment for validating an implementation
of their generator:

     seed := 1;
     for n := 1 to 10000 do
       u := random(seed);
     writeln(seed);

The resultant value must be 1043618065.  The article has a theory section
wherein claims about the generator are proved(?) but I didn't copy it.
They also speculated about other values of a and m but weren't ready to 
make any claims about them.

Philip Munts N7AHL
NRA Extremist, etc.
University of Alaska, Fairbanks