This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/math/distribution/Uniform.h
FrankE 62d8d6b36b refactored random subsystem
added compile-time seed support
2016-04-26 15:15:28 +02:00

45 lines
809 B
C++

#ifndef UNIFORM_H
#define UNIFORM_H
#include <cmath>
#include <random>
#include "../Random.h"
#include <type_traits>
namespace Distribution {
/** uniform distribution */
template <typename T> class Uniform {
private:
RandomGenerator gen;
/** depending on T, Dist is either a uniform_real or uniform_int distribution */
typedef typename std::conditional< std::is_floating_point<T>::value, std::uniform_real_distribution<T>, std::uniform_int_distribution<T> >::type Dist;
Dist dist;
public:
/** ctor */
Uniform(const T min, const T max) : gen(RANDOM_SEED), 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