mardi 27 juin 2017

Boost Random Generators returning identical values

Looking for a boost random expert... I need to generate random numbers in between many, many different ranges. I've written the below functions:

boost:mt19937 m_oRng;

int generateIntVariate(int p_iMin, int p_iMax){
  boost::uniform_int<> min_to_max(p_iMin, p_iMax);
  boost::variate_generator< boost::mt19937, boost::uniform_int<> > oGen(m_oRng, min_to_max);
  return oGen();
}

float generateFloatVariate(int p_fMin, p_fMax){
  boost::uniform_real<> min_to_max(p_fMin, p_fMax);
  boost::variate_generator< boost::mt19937, boost::uniform_real<> > oGen(m_oRng, min_to_max);
  return oGen();
}

The problem is that both functions return the same exact number for a given range, every time it's executed.

(gdb) p generateIntVariation(0, 10)
$40 = 8
(gdb) p generateIntVariation(0, 10)
$41 = 8
(gdb) p generateIntVariation(0, 10)
$42 = 8
(gdb) p generateIntVariation(0, 10)
$43 = 8

The same thing as above happens with the float function. Is there any way I can accomplish what I'm trying to do using the boost random distros?




Aucun commentaire:

Enregistrer un commentaire