#include "stdafx.h"
#include <iostream>
#include <list>
#include <iterator>
#include <math.h>
#include <TIME.H>
using namespace std;
#define M_PI 3.14
class randNbs
{
public:
void Display()
{
cout<< "***X coordinates***" << endl;
for(list<double>::iterator itList=(myXs.begin()); itList!=(myXs.end()); itList++)
{
cout<< (*itList) << endl;
}
cout<< "***Y coordinates***" << endl;
for(list<double>::iterator itList=(myYs.begin()); itList!=(myYs.end()); itList++)
{
cout<< (*itList) << endl;
}
}
randNbs (int dimension, double miu, double sigma, double min, double max)
{
srand ( time(NULL) );
for (int i = 0; i<dimension; i++){
double temp = NormalRandom(miu, sigma, min, max);
myXs.push_back(temp);
myYs.push_back(Normal(temp, miu, sigma));
}
}
protected:
double AverageRandom(double min,double max)
{
int nbRand = rand() % 10001;
return (min + nbRand*(max-min)/10000);
}
double Normal(double x,double miu,double sigma)
{
return 1.0/sqrt(2*M_PI*sigma) * exp(-1*(x-miu)*(x-miu)/(2*sigma*sigma));
}
double NormalRandom(double miu, double sigma,double min,double max)
{
double x;
double dScope;
double y;
do
{
x = AverageRandom(min,max);
y = Normal(x, miu, sigma);
dScope = AverageRandom(0, Normal(miu,miu,sigma));
}while( dScope > y);
return x;
}
list <double> myXs, myYs;
};
int main() {
randNbs *myNbs = new randNbs(100, 0, 1, -3, 3);
myNbs->Display();
return 0;
}