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