forked from rurban/smhasher
-
Notifications
You must be signed in to change notification settings - Fork 10
/
AvalancheTest.cpp
57 lines (40 loc) · 1.05 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
57
#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");
fflush(NULL);
}
}
//----------------------------------------------------------------------------
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;
}
//-----------------------------------------------------------------------------