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

Dirk Eddelbuettel edd at debian.org
Thu Feb 3 02:08:05 CET 2011


On 2 February 2011 at 23:45, Barry Rowlingson wrote:
| 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

And/or the DieHarder test by Robert G Brown et al -- and with that the
RDieHarder package on CRAN which wraps.  (And I need to catch up to the fresh
development in DieHarder

Dirk 

| Barry
| 
| ______________________________________________
| R-help at r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-help
| PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
| and provide commented, minimal, self-contained, reproducible code.

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com



More information about the R-help mailing list