1 /*
2 * $Id: diehard_craps.c 191 2006-07-13 08:23:50Z rgb $
3 *
4 * See copyright in copyright.h and the accompanying file COPYING
5 *
6 */
7
8 /*
9 *========================================================================
10 *========================================================================
11 */
12
13 #include <dieharder/libdieharder.h>
14
marsaglia_tsang_gorilla(Test ** test,int irun)15 void marsaglia_tsang_gorilla(Test **test, int irun)
16 {
17
18 uint t,i,lag;
19 Xtest ptest;
20
21 /*
22 * ptest.x = actual sum of test[0]->tsamples lagged samples from rng
23 * ptest.y = test[0]->tsamples*0.5 is the expected mean value of the sum
24 * ptest.sigma = sqrt(test[0]->tsamples/12.0) is the standard deviation
25 */
26 ptest.x = 0.0; /* Initial value */
27 ptest.y = (double) test[0]->tsamples*0.5;
28 ptest.sigma = sqrt(test[0]->tsamples/12.0);
29
30 /*
31 * sample only every lag returns from the rng, discard the rest.
32 * We have to get the (float) value from the user input and set
33 * a uint
34 */
35 if(x_user){
36 lag = x_user;
37 } else {
38 lag = 2; /* Why not? Anything but 0, really... */
39 }
40
41 if(verbose == D_USER_TEMPLATE || verbose == D_ALL){
42 printf("# marsaglia_tsang_gorilla(): Doing a test on lag %u\n",lag);
43 }
44
45 for(t=0;t<test[0]->tsamples;t++){
46
47 /*
48 * A VERY SIMPLE test (probably not too sensitive)
49 */
50
51 /* Throw away lag-1 per sample */
52 for(i=0;i<(lag-1);i++) gsl_rng_uniform(rng);
53
54 /* sample only every lag numbers, reset counter */
55 ptest.x += gsl_rng_uniform(rng);
56
57 }
58
59 Xtest_eval(&ptest);
60 test[0]->pvalues[irun] = ptest.pvalue;
61
62 MYDEBUG(D_MARSAGLIA_TSANG_GORILLA) {
63 printf("# marsaglia_tsang_gorilla(): test[0]->pvalues[%u] = %10.5f\n",irun,test[0]->pvalues[irun]);
64 }
65
66 }
67
68