1 /*
2  * $Id: rgb_persist.c 250 2006-10-10 05:02:26Z rgb $
3  *
4  * See copyright in copyright.h and the accompanying file COPYING
5  */
6 
7 /*
8  *========================================================================
9  * This is a test that checks to see if all the bits returned by the
10  * rng change.  Surprisingly, several generators have bits that do NOT
11  * change, hence the test.  It also reveals tests that for whatever reason
12  * return less than the expected uint number of bits (32) as unchanging
13  * high bits
14  *
15  * This (and all further rgb_ tests) are "my own".  Some of them may turn
16  * out to be formally equivalent to diehard or sts or knuth tests in the
17  * specific sense that failure in one always matches or precedes failure
18  * in the other.
19  *========================================================================
20  */
21 
22 #include <dieharder/libdieharder.h>
23 
rgb_persist(Test ** test,Rgb_Persist * persist)24 int rgb_persist(Test **test, Rgb_Persist *persist)
25 {
26 
27  uint last_rand;
28  int i,j;
29 
30  /*
31   * Now go through the list and dump the numbers several ways.
32   */
33  if(bits > 32) {
34    persist->nbits = 32;
35  } else {
36    persist->nbits = bits;
37  }
38 
39  persist->cumulative_mask = 0;
40  for(j=0;j<psamples;j++){
41    /*
42     * Do not reset the total count of rands or rewind file input
43     * files -- let them auto-rewind as needed.  Otherwise try
44     * different seeds for different samples.
45     */
46    if(strncmp("file_input",gsl_rng_name(rng),10)){
47      seed = random_seed();
48      gsl_rng_set(rng,seed);
49    }
50    /*
51     * Fill rgb_persist_rand_uint with a string of random numbers
52     */
53    for(i=0;i<256;i++) rgb_persist_rand_uint[i] = gsl_rng_get(rng);
54    last_rand = rgb_persist_rand_uint[0];  /* to start it */
55    persist->and_mask = ~(last_rand ^ rgb_persist_rand_uint[0]);
56    for(i=0;i<256;i++){
57      if(verbose){
58        printf("rgb_persist_rand_uint[%d] = %u = ",i,rgb_persist_rand_uint[i]);
59        dumpbits(&rgb_persist_rand_uint[i],persist->nbits);
60        printf("\n");
61      }
62 
63      /*
64       * Now we make a mask of bits that coincide. Logic 41, where are you?
65       */
66      persist->and_mask = persist->and_mask & (~(last_rand ^ rgb_persist_rand_uint[i]));
67      if(verbose){
68        printf("and_mask = %u = ",persist->and_mask);
69        dumpbits(&persist->and_mask,persist->nbits);
70        printf("\n");
71      }
72 
73    }
74    persist->and_mask = persist->and_mask & rmax_mask;
75    persist->cumulative_mask = persist->cumulative_mask | persist->and_mask;
76  }
77 
78  return(0);
79 
80 }
81 
82