1 /*
2  * ========================================================================
3  * $Id: diehard_birthdays.c 250 2006-10-10 05:02:26Z rgb $
4  *
5  * See copyright in copyright.h and the accompanying file COPYING
6  * ========================================================================
7  */
8 
9 /*
10  * ========================================================================
11  * This is the Diehard BINARY RANK 6x8 test, rewritten from the
12  * description in tests.txt on George Marsaglia's diehard site.
13  *
14  * This is the BINARY RANK TEST for 6x8 matrices.  From each of  ::
15  * six random 32-bit integers from the generator under test, a   ::
16  * specified byte is chosen, and the resulting six bytes form a  ::
17  * 6x8 binary matrix whose rank is determined.  That rank can be ::
18  * from 0 to 6, but ranks 0,1,2,3 are rare; their counts are     ::
19  * pooled with those for rank 4. Ranks are found for 100,000     ::
20  * random matrices, and a chi-square test is performed on        ::
21  * counts for ranks 6,5 and <=4.                                 ::
22  *
23  * ===================================================================
24  */
25 
26 #include <dieharder/libdieharder.h>
27 
28 /*
29  * Include inline uint generator
30  */
31 #include "static_get_bits.c"
32 
diehard_rank_6x8(Test ** test,int irun)33 int diehard_rank_6x8(Test **test, int irun)
34 {
35 
36 
37  int i,t,rank;
38  uint bitstring;
39  uint **mtx;
40  Vtest vtest;
41 
42  MYDEBUG(D_DIEHARD_RANK_6x8){
43    fprintf(stdout,"# diehard_rank_6x8():  Starting test.\n");
44  }
45 
46  /*
47   * for display only.  0 means "ignored".
48   */
49  test[0]->ntuple = 0;
50 
51  mtx = (uint **)malloc(6*sizeof(uint *));
52  for(i=0;i<6;i++){
53    mtx[i] = (uint *)malloc(8*sizeof(uint));
54  }
55 
56  Vtest_create(&vtest,7);
57  vtest.cutoff = 5.0;
58  for(i=0;i<2;i++){
59    vtest.x[0] = 0.0;
60    vtest.y[0] = 0.0;
61  }
62  vtest.x[2] = 0.0;
63  vtest.y[2] = test[0]->tsamples*0.149858E-06;
64  vtest.x[3] = 0.0;
65  vtest.y[3] = test[0]->tsamples*0.808926E-04;
66  vtest.x[4] = 0.0;
67  vtest.y[4] = test[0]->tsamples*0.936197E-02;
68  vtest.x[5] = 0.0;
69  vtest.y[5] = test[0]->tsamples*0.217439E+00;
70  vtest.x[6] = 0.0;
71  vtest.y[6] = test[0]->tsamples*0.773118E+00;
72 
73  for(t=0;t<test[0]->tsamples;t++){
74 
75    /*
76     * We generate 6 random rmax_bits-bit integers and put a
77     * randomly chosen byte into the LEFTMOST byte position
78     * of the row/slot of mtx.
79     */
80    MYDEBUG(D_DIEHARD_RANK_6x8){
81      fprintf(stdout,"# diehard_rank_6x8(): Input random matrix = \n");
82    }
83    for(i=0;i<6;i++){
84      MYDEBUG(D_DIEHARD_RANK_6x8){
85        fprintf(stdout,"# ");
86      }
87 
88      bitstring = get_rand_bits_uint(32,0xffffffff,rng);
89      mtx[i][0] = bitstring;
90 
91      MYDEBUG(D_DIEHARD_RANK_6x8){
92        dumpbits(mtx[i],32);
93        fprintf(stdout,"\n");
94      }
95    }
96 
97    rank = binary_rank(mtx,6,8);
98    MYDEBUG(D_DIEHARD_RANK_6x8){
99      printf("binary rank = %d\n",rank);
100    }
101 
102    if(rank <= 2){
103      vtest.x[2]++;
104    } else {
105      vtest.x[rank]++;
106    }
107  }
108 
109  /* for(i=0;i<33;i++) printf("vtest.x[%d] =  %f\n",i,vtest.x[i]); */
110 
111  Vtest_eval(&vtest);
112  test[0]->pvalues[irun] = vtest.pvalue;
113  MYDEBUG(D_DIEHARD_RANK_6x8) {
114    printf("# diehard_rank_6x8(): test[0]->pvalues[%u] = %10.5f\n",irun,test[0]->pvalues[irun]);
115  }
116 
117  Vtest_destroy(&vtest);
118 
119  for(i=0;i<6;i++){
120    free(mtx[i]);
121  }
122  free(mtx);
123 
124  return(0);
125 
126 }
127 
128