I tried to create a series of random numbers using uniform distribution whose limits are given from a file.
void initialize ( string file_in_name )
{
ifstream file_in;
int i;
int j;
//lbound= lower value bound, ubound=upper value bound
double lbound;
double ubound;
file_in.open ( file_in_name.c_str ( ) );
if ( !file_in )
{
cout << "\n";
cout << "Initialize - Fatal error!\n";
cout << " Cannot open the input file!\n";
exit ( 1 );
}
//
// Initialize variables within the bounds
//
for ( i = 0; i < NVARS; i++ )
{
file_in >> lbound >> ubound;
for ( j = 0; j < POPSIZE; j++ )
{
population[j].lower[i] = lbound;
population[j].upper[i]= ubound;
population[j].value[i] = randval ( population[j].lower[i],population[j].upper[i] );
}
}
file_in.close ( );
return;
}
where randval is the following function
double randval ( double low, double high )
{
double val;
mt19937 generator;
uniform_real<double> distribution(low, high);
val = distribution(generator);
return ( val );
}
The distribution I use is from tr1/random, but every time I use execute the code, the results are out of bounds. To be more specific, the file I give has lower and upper bounds equal to -180 and 180 respectively and the values are of order 10^12.
What could be the problem?
Aucun commentaire:
Enregistrer un commentaire