summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Base')
-rw-r--r--Swiften/Base/BoostRandomGenerator.cpp15
-rw-r--r--Swiften/Base/BoostRandomGenerator.h2
-rw-r--r--Swiften/Base/RandomGenerator.h2
3 files changed, 6 insertions, 13 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);
}
}
diff --git a/Swiften/Base/BoostRandomGenerator.h b/Swiften/Base/BoostRandomGenerator.h
index ffc7a72..6d65b0b 100644
--- a/Swiften/Base/BoostRandomGenerator.h
+++ b/Swiften/Base/BoostRandomGenerator.h
@@ -13,7 +13,7 @@
namespace Swift {
class BoostRandomGenerator : public RandomGenerator{
public:
- int generateWeighedRandomNumber(std::vector<double>::const_iterator probabilities_begin, std::vector<double>::const_iterator probabilities_end);
+ int generateRandomInteger(int max);
private:
boost::mt19937 generator;
diff --git a/Swiften/Base/RandomGenerator.h b/Swiften/Base/RandomGenerator.h
index a998e0d..4a3550d 100644
--- a/Swiften/Base/RandomGenerator.h
+++ b/Swiften/Base/RandomGenerator.h
@@ -13,6 +13,6 @@ namespace Swift {
public:
virtual ~RandomGenerator();
- virtual int generateWeighedRandomNumber(std::vector<double>::const_iterator probabilities_begin, std::vector<double>::const_iterator probabilities_end) = 0;
+ virtual int generateRandomInteger(int max) = 0;
};
}