39 lines
550 B
C++
39 lines
550 B
C++
#ifndef UNIFORM_H
|
|
#define UNIFORM_H
|
|
|
|
#include <cmath>
|
|
#include <random>
|
|
|
|
namespace Distribution {
|
|
|
|
/** uniform distribution */
|
|
template <typename T> class Uniform {
|
|
|
|
private:
|
|
|
|
std::minstd_rand gen;
|
|
std::uniform_real_distribution<T> dist;
|
|
|
|
public:
|
|
|
|
/** ctor */
|
|
Uniform(const T min, const T max) :
|
|
gen(1234), dist(min, max) {
|
|
|
|
}
|
|
/** get a uniformaly distributed random number */
|
|
T draw() {
|
|
return dist(gen);
|
|
}
|
|
|
|
/** set the seed to use */
|
|
void setSeed(const long seed) {
|
|
gen.seed(seed);
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif // UNIFORM_H
|