I wrote the following class to generate random integers from a given interval [lower, upper].
class RandomInteger {
protected:
std::random_device randomDevice;
std::default_random_engine randomEngine;
std::uniform_int_distribution<> distribution;
public:
RandomInteger(int64_t lower, int64_t upper);
virtual ~RandomInteger();
virtual int64_t generate();
};
RandomInteger::RandomInteger(int64_t lower, int64_t upper) : randomEngine(this->randomDevice()), distribution(lower, upper) {
}
RandomInteger::~RandomInteger() {
}
int64_t RandomInteger::generate() {
int64_t i = this->distribution(this->randomEngine);
return i;
}
This is normal if the interval remains the same and several calls are made generate. However, now my use case generates integers from an interval that always changes (the upper bound increases every time).
First of all, it should be quick. This has nothing to do with cryptography, so very pseudorandom numbers are fine (and std::random_deviceprobably not required). I would also like to avoid the C style, if possible, and use the modern C ++ 11 style.
Can you suggest ways to do this effectively?