1  /****************************************************************************


2  FILE : random_test.c


3  SUBJECT : Random number generator test program.


4  PROGRAMMER: (C) Copyright 2012 by Peter C. Chapin


5 


6  Although there are RNG test suites out there, I thought it would be instructive to write a few


7  tests "manually".


8 


9  ****************************************************************************/


10 


11  #include <iostream>


12  #include <iomanip>


13  #include "random.h"


14 


15  int *bucket_array[16];


16 


17  unsigned current;


18  const int mask[16] = {


19  0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF,


20  0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF


21  };


22 


23  int main(void)


24  {


25  // Set up the generator.


26  rnd::standard_random base_gen;


27  base_gen.time_seed();


28  rnd::bit_random gen(base_gen);


29 


30  // Allocate the bucket arrays.


31  int i, size;


32  for (i = 0, size = 2; i < 16; ++i, size *= 2) {


33  bucket_array[i] = new int[size];


34  for (int j = 0; j < size; ++j) bucket_array[i][j] = 0;


35  }


36 


37  // Generate random bits and catagorize the results.


38  for (i = 0; i < 1000000; ++i) {


39  current = (current << 1)  gen.next();


40  for (int j = 0; j < 16; ++j) {


41  bucket_array[j][current & mask[j]]++;


42  }


43  }


44 


45  // This is just for now. Need to do Chisquared analysis of results.


46  for (i = 0; i < 2; ++i) {


47  std::cout << std::setw(7) << bucket_array[0][i];


48  }


49  std::cout << "\n";


50  for (i = 0; i < 4; ++i) {


51  std::cout << std::setw(7) << bucket_array[1][i];


52  }


53  std::cout << "\n";


54  for (i = 0; i < 8; ++i) {


55  std::cout << std::setw(7) << bucket_array[2][i];


56  }


57  std::cout << "\n";


58  return 0;


59  }

