Commit e0611b9c authored by Ogier Maitre's avatar Ogier Maitre

Segfault resolved. Correct initialization of the random generator.

parent 3fd5741e
......@@ -17,6 +17,10 @@ CRandomGenerator::CRandomGenerator(unsigned int seed){
//srand(seed);
}
CRandomGenerator::~CRandomGenerator(){
delete this->mt_rnd;
}
int CRandomGenerator::randInt(){
//return rand();
return mt_rnd->randInt();
......
......@@ -16,6 +16,7 @@ class CRandomGenerator {
MTRand* mt_rnd;
public:
CRandomGenerator(unsigned int seed);
~CRandomGenerator();
int randInt();
bool tossCoin();
bool tossCoin(float bias);
......
......@@ -214,6 +214,11 @@ size_t IndividualImpl::mutate( float pMutationPerGene ){
}
void ParametersImpl::setDefaultParameters(int argc, char** argv){
seed = setVariable("seed",(int)time(0));
globalRandomGenerator = new CRandomGenerator(seed);
this->randomGenerator = globalRandomGenerator;
this->minimizing = \MINIMAXI;
this->nbGen = setVariable("nbGen",(int)\NB_GEN);
......@@ -279,9 +284,6 @@ void ParametersImpl::setDefaultParameters(int argc, char** argv){
this->optimise = 0;
seed = setVariable("seed",(int)time(0));
globalRandomGenerator = new CRandomGenerator(seed);
this->randomGenerator = globalRandomGenerator;
this->printStats = setVariable("printStats",\PRINT_STATS);
this->generateCSVFile = setVariable("generateCSVFile",\GENERATE_CSV_FILE);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment