2017-03-25 20:12:56 +00:00
|
|
|
/// Taken from SMHasher.
|
2014-05-21 02:19:44 +00:00
|
|
|
|
|
|
|
#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++)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
printf("[");
|
|
|
|
for(int j = 0; j < x; j++)
|
|
|
|
{
|
|
|
|
int k = (y - i) -1;
|
2014-05-21 02:19:44 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
int bin = bins[k + (j*y)];
|
2014-05-21 02:19:44 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
double b = double(bin) / double(reps);
|
|
|
|
b = fabs(b*2 - 1);
|
2014-05-21 02:19:44 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
b *= scale;
|
2014-05-21 02:19:44 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
int s = static_cast<int>(floor(b*10));
|
2014-05-21 02:19:44 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if(s > 10) s = 10;
|
|
|
|
if(s < 0) s = 0;
|
2014-05-21 02:19:44 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
printf("%c",symbols[s]);
|
|
|
|
}
|
2014-05-21 02:19:44 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
printf("]\n");
|
2014-05-21 02:19:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
double maxBias ( std::vector<int> & counts, int reps )
|
|
|
|
{
|
|
|
|
double worst = 0;
|
|
|
|
|
2016-08-25 21:55:02 +00:00
|
|
|
for(int i = 0; i < static_cast<int>(counts.size()); i++)
|
2014-05-21 02:19:44 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
double c = static_cast<double>(counts[i]) / static_cast<double>(reps);
|
2014-05-21 02:19:44 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
double d = fabs(c * 2 - 1);
|
2016-08-25 21:55:02 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if(d > worst)
|
|
|
|
{
|
|
|
|
worst = d;
|
|
|
|
}
|
2014-05-21 02:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return worst;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|