Skip to content

Instantly share code, notes, and snippets.

@hcatlin

hcatlin/match.c

Created Aug 18, 2015
Embed
What would you like to do?
#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