[R] testing randomness of random number generators with student t-test?

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Thu Feb 3 00:45:26 CET 2011


On Wed, Feb 2, 2011 at 11:01 PM, Carl Witthoft <carl at witthoft.com> wrote:
> Hi, subject more or less says it all.
>
> I freely admit to not having bothered to find some of the online papers
> about method of testing the quality of random number generators -- but in an
> idle moment I wondered what to expect from something like the following:
>
>
> randa<-runif(1000)
> randb<-runif(1000)
> t.test(randa,randb)$p.value
> var.test(randa,randb)$p.value
>
> [repeat ad nauseum]
>
>
> Is the range of p-values I get in any way related tothe "quality" of the
> random number generator?

 Well yes. All pseudo random number generators have a period, after
which they come back to the start and begin churning out the same
sequence again. Good PRNGs have a sequence length that is
astronomically high. If you have a PRNG that has a sequence of 1000,
or 500, or 200 etc your two sets will be perfectly correlated...

 You might want to read up on RANDU, the infamous poor PRNG:

 http://en.wikipedia.org/wiki/RANDU

“We guarantee that each number is random individually, but we don’t
guarantee that more than one of them is random.”

The other things to look at are the DieHard tests:
http://en.wikipedia.org/wiki/Diehard_test

Barry



More information about the R-help mailing list