AvalancheTest.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "AvalancheTest.h"
  2. //-----------------------------------------------------------------------------
  3. void PrintAvalancheDiagram ( int x, int y, int reps, double scale, int * bins )
  4. {
  5. const char * symbols = ".123456789X";
  6. for(int i = 0; i < y; i++)
  7. {
  8. printf("[");
  9. for(int j = 0; j < x; j++)
  10. {
  11. int k = (y - i) -1;
  12. int bin = bins[k + (j*y)];
  13. double b = double(bin) / double(reps);
  14. b = fabs(b*2 - 1);
  15. b *= scale;
  16. int s = (int)floor(b*10);
  17. if(s > 10) s = 10;
  18. if(s < 0) s = 0;
  19. printf("%c",symbols[s]);
  20. }
  21. printf("]\n");
  22. }
  23. }
  24. //----------------------------------------------------------------------------
  25. double maxBias ( std::vector<int> & counts, int reps )
  26. {
  27. double worst = 0;
  28. for(int i = 0; i < (int)counts.size(); i++)
  29. {
  30. double c = double(counts[i]) / double(reps);
  31. double d = fabs(c * 2 - 1);
  32. if(d > worst)
  33. {
  34. worst = d;
  35. }
  36. }
  37. return worst;
  38. }
  39. //-----------------------------------------------------------------------------