summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swiften/Base/BoostRandomGenerator.cpp5
-rw-r--r--Swiften/Base/BoostRandomGenerator.h2
2 files changed, 7 insertions, 0 deletions
diff --git a/Swiften/Base/BoostRandomGenerator.cpp b/Swiften/Base/BoostRandomGenerator.cpp
index 62c3055..e58ec95 100644
--- a/Swiften/Base/BoostRandomGenerator.cpp
+++ b/Swiften/Base/BoostRandomGenerator.cpp
@@ -6,15 +6,20 @@
#include <Swiften/Base/BoostRandomGenerator.h>
#include <numeric>
#include <boost/random/uniform_int.hpp>
#include <boost/random/variate_generator.hpp>
namespace Swift {
+BoostRandomGenerator::BoostRandomGenerator() {
+ // FIXME: Not a good seed
+ generator.seed(static_cast<unsigned int>(std::time(0)));
+}
+
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 6d65b0b..b5a6cac 100644
--- a/Swiften/Base/BoostRandomGenerator.h
+++ b/Swiften/Base/BoostRandomGenerator.h
@@ -7,15 +7,17 @@
#pragma once
#include <Swiften/Base/RandomGenerator.h>
#include <boost/random/mersenne_twister.hpp>
namespace Swift {
class BoostRandomGenerator : public RandomGenerator{
public:
+ BoostRandomGenerator();
+
int generateRandomInteger(int max);
private:
boost::mt19937 generator;
};
}