summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2012-04-23 16:11:21 (GMT)
committerRemko Tronçon <git@el-tramo.be>2012-04-23 16:11:21 (GMT)
commit7bd058600b682781abb3fd93bfaf516e7d8d7b23 (patch)
tree56ee7619b3785ff09a15ffdb54ac6427cd052dbf /Swiften/Base
parent00981790bc39e9a0674feec19ffa792329bb077c (diff)
downloadswift-contrib-7bd058600b682781abb3fd93bfaf516e7d8d7b23.zip
swift-contrib-7bd058600b682781abb3fd93bfaf516e7d8d7b23.tar.bz2
Another fix for SRV selection.
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;
};
}