diff options
Diffstat (limited to 'Swiften/Base/BoostRandomGenerator.cpp')
-rw-r--r-- | Swiften/Base/BoostRandomGenerator.cpp | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/Swiften/Base/BoostRandomGenerator.cpp b/Swiften/Base/BoostRandomGenerator.cpp index b8c50d0..62c3055 100644 --- a/Swiften/Base/BoostRandomGenerator.cpp +++ b/Swiften/Base/BoostRandomGenerator.cpp @@ -7,21 +7,14 @@ #include <Swiften/Base/BoostRandomGenerator.h> #include <numeric> -#include <boost/random/uniform_real.hpp> +#include <boost/random/uniform_int.hpp> #include <boost/random/variate_generator.hpp> namespace Swift { -int BoostRandomGenerator::generateWeighedRandomNumber(std::vector<double>::const_iterator probabilities_begin, std::vector<double>::const_iterator probabilities_end) { - // Only works starting boost 1.47 - //boost::random::discrete_distribution<> distribution(weights.begin(), weights.end()); - //return distribution(generator); - - std::vector<double> cumulative; - std::partial_sum(probabilities_begin, probabilities_end, std::back_inserter(cumulative)); - boost::uniform_real<> dist(0, cumulative.back()); - boost::variate_generator<boost::mt19937&, boost::uniform_real<> > die(generator, dist); - return std::lower_bound(cumulative.begin(), cumulative.end(), die()) - cumulative.begin(); +int BoostRandomGenerator::generateRandomInteger(int maximum) { + boost::uniform_int<> distribution(0, maximum); + return distribution(generator); } } |