Created
August 18, 2015 15:55
-
-
Save HamptonMakes/13cf323a3ff07a0b881d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
int random() { | |
FILE *fp; | |
if ((fp = fopen("/dev/random", "r")) == NULL){ | |
return 0; | |
} | |
return fgetc(fp); | |
} | |
double compareArraysAtRandomIndex(double * test, double * reference, int bins) { | |
int sampleIndex = (bins - (random() % bins)); | |
if(bins <= sampleIndex) { return 0; } | |
return(fabs(test[sampleIndex] - reference[sampleIndex])); | |
} | |
int match(double * test, double * reference, int bins, double threshold) { | |
int samples = bins / 5; | |
if(samples <= 0) { //Make sure we are testing something! | |
samples = 1; | |
} | |
for(int i = 0; i < samples; i++) { | |
if(compareArraysAtRandomIndex(test, reference, bins) > threshold) { | |
return 0; | |
}; | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment