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
|
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
using namespace std;
int main(){
float t=0;
float y=0;
float z;
int size=5000;
int x=0;
int 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
if (z>=y){
it=floor(2*t); //bin number
bin[it]=bin[it]+1; //I think it SHOULD add one to current bin??
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
}
}
}
|