1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
using namespace std;
int main()
{
float t=0, y=0, z;
int size=5000, x=0,it;
int bin[60]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
while(x<size)
{
t= (rand() % 30001)/1000.0; //gives random number between 0 and 30
y= (rand() % 1001)/1000.0; //gives random number between 0 and 1
z= (exp(-t/3.896)+(72.433/28209.33)); //exponential curve to check if y is under
cout << t << endl;
cout << z << endl;
cout << y << endl;
system("pause");
if (z>=y)
{
it=floor(2*t); //bin number
cout << it << endl;
cout << bin[it] << endl;
system("pause");
bin[it]=bin[it]+1; //I think it SHOULD add one to current bin??
cout << bin[it] << endl;
system("pause");
x=x+1; //increment x
//cout << t << " " << y << " " << it << endl;
}
for(int l=0; l<60; l++)
{
cout << bin[l] << endl; //display number of counts in each bin
}
}
}
|