#include "Intel_Compatibility.h"
#include "dSFMT.h"
#include <iostream>
#include <ctime>

#define HEIGHT 8

using namespace std;

int main()
{
	cout << "RUNNING FALCON = LINEAR with HEIGHT = " << HEIGHT << std::endl;
	
	double *alpha = new double[HEIGHT];
	double sum = 0.0;
	
	dsfmt_t dsfmt;
	dsfmt_init_gen_rand(&dsfmt, 10235);
	
	// initialize the array
	for(int i = 0; i < HEIGHT; i++)
	{
		alpha[i] = dsfmt_genrand_close_open(&dsfmt);
		sum += alpha[i];
	}
	
	for(int i = 0; i < HEIGHT; i++)
		alpha[i] /= sum;
	
	int numTimes = 1000000000;
	
	cout << "Timing Falcon for " << numTimes << std::endl;
	
	int p = 0;
	
	// Start timing here
	long timeStart = clock();
	
	// Now do this like 1000000 times
	for(int i = 0; i < numTimes; i++)
	{
		// Generate a random number, and try to find it in alpha
		double randNum = dsfmt_genrand_close_open(&dsfmt);
		
		for(int j = 0; j < HEIGHT; j++)
			if(randNum <= alpha[j])
			{
				p += j;
				break;
			}
			else
				randNum -= alpha[j];
	}
	
	// End Timing here
	long timeEnd = clock();

	cout << "Consumed a total of " << timeEnd - timeStart << " milliseconds." << std::endl;
	
	return 0;
}
