Skip to content

Instantly share code, notes, and snippets.

@HamptonMakes
Created August 18, 2015 15:55
Show Gist options
  • Save HamptonMakes/13cf323a3ff07a0b881d to your computer and use it in GitHub Desktop.
Save HamptonMakes/13cf323a3ff07a0b881d to your computer and use it in GitHub Desktop.
#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