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