blob: f5ea0df95592d6aa7dcf0765663c9c68eaff2686 [file] [log] [blame]
tanjent@gmail.comf3b78972012-03-01 03:38:55 +00001#include "AvalancheTest.h"
2
3//-----------------------------------------------------------------------------
4
5void 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
37double 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//-----------------------------------------------------------------------------