///
/// \param min The minimum number in the range
/// \param max The maximum number in the range
- /// \param seed A seed for the RNG. If 0 is passed, the current time
- /// is used.
- UniformRandomIntegerGenerator(int min, int max, unsigned int seed = 0):
+ UniformRandomIntegerGenerator(int min, int max):
min_(std::min(min, max)), max_(std::max(min, max)),
dist_(min_, max_), generator_(rng_, dist_)
{
}
// Init with the current time
- if (seed == 0) {
- seed = time(NULL);
- }
- rng_.seed(seed);
+ rng_.seed(time(NULL));
}
/// \brief Generate uniformly distributed integer
#include <boost/shared_ptr.hpp>
#include <iostream>
-#include <climits>
-#include <sys/types.h>
-#include <unistd.h>
namespace isc {
namespace util {
ASSERT_EQ(it - numbers.begin(), max() - min() + 1);
}
-TEST_F(UniformRandomIntegerGeneratorTest, withSeed) {
- // Test that two generators with the same seed return the same
- // sequence.
- UniformRandomIntegerGenerator gen1(0, INT_MAX, getpid());
- vector<int> numbers;
- for (int i = 0; i < 1024; ++i) {
- numbers.push_back(gen1());
- }
-
- UniformRandomIntegerGenerator gen2(0, INT_MAX, getpid());
- for (int i = 0; i < 1024; ++i) {
- EXPECT_EQ(numbers[i], gen2());
- }
-}
-
/// \brief Test Fixture Class for weighted random number generator
class WeightedRandomIntegerGeneratorTest : public ::testing::Test {
public: