//A RNG testing program, Dale Swanson - Nov 19 2006

#include <cstdlib>
#include <iostream>
#include <fstream.h>
#include <math.h>

using namespace std;
int x;
double y;
int z;
int num[111];
int bit; //counts number of bits gen so far
int byte; //counts number of bytes gen so far
int rann; //will be the ran number returned
int min; //min random number
int max; //max ran number
int word[50]; //will be an arrary the holds the binnary form of our number
int test;
int one, two, sone, stwo;
int powtwo;
int comp;

double ran(double a, double b) //returns a random number between a min, and b max
{
	int k; //used for killing some random numbers (k is a random letter I picked, but let's pretend I picked it to stand for kill)
	double range; //range from you min and max
	double c = 0; //this is your real random number that will be used to return
	range = (b - a) + 1;
	if (rand() == 138) srand(rand() + clock()); 
	//1 in 32k odds to reseed the RNG uses both a rand number and the clock (clock isn't seconds, it's system ticks, faster than seconds) 
	if ((rand() + clock()) % 5 == 1) 
	//basicly 1 in 5 chance of looping a wasting some random numbers
	{
		for (k = ((clock() % 4) + ((rand() + clock()) % 7) + (rand() % 18) + 9); k > 0; k--)//comes up with a number to loop from about 9 to 35 times
		{
			rand(); //wastes some random numbers
		}
	}
	c = a + int(range * rand() / (RAND_MAX + 1));
   return c;
}

int main(int argc, char *argv[])
{
    time_t sseconds; //should seed the random number generator
	time_t cseconds;
    time_t tsec; 
    time(&sseconds);
    srand((unsigned int) sseconds);
	cout<<"\nTime - "<<time(&tsec);
	
	powtwo = 24;
	
	for (x=1; ; x++)
	{

		test = int(ran(1,2));
		if (test == 1) 
		{
			one++;
			if (two > stwo) stwo = two;
			two = 0;
		}
		
		else if (test == 2)
		{
			two++;
			if (one > sone) sone = one;
			one = 0;
		}
		
		if (x == 131072)
		{
			time(&cseconds);
			cout<<"\n131072, 17 Streak, Time - "<<cseconds - sseconds<<", Longest streaks, 1 - "<<sone<<", 2 - "<<stwo;
			cout<<"\nClock - "<<clock();
		}
		
		else if (x == 1048576)
		{
			time(&cseconds);
			cout<<"\n1048576, 20 Streak, Time - "<<cseconds - sseconds<<", Longest streaks, 1 - "<<sone<<", 2 - "<<stwo;
			cout<<"\nClock - "<<clock();
		}
		
		else if (x == 8388608)
		{
			time(&cseconds);
			cout<<"\n8388608, 23 Streak, Time - "<<cseconds - sseconds<<", Longest streaks, 1 - "<<sone<<", 2 - "<<stwo;
			cout<<"\nClock - "<<clock();
			powtwo = 24;
		}
		
		else if (x == pow(2, powtwo))
		{
			time(&cseconds);
			cout<<"\n2^"<<powtwo<<" Streak, Time - "<<cseconds - sseconds<<", Longest streaks, 1 - "<<sone<<", 2 - "<<stwo;
			cout<<"\nClock - "<<clock();
			powtwo++;
		}		
		
	}
	
    system("PAUSE");
    return EXIT_SUCCESS;
}
