Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RandomWrapper
#include <random>
template<typename T>
class RandomWrapper
{
public:
RandomWrapper() : data(dist(rng)) {
}
operator T() { return data; }
static int getSeed() {
const int hour = std::atoi(__TIME__);
const int min = std::atoi(__TIME__ + 3);
const int sec = std::atoi(__TIME__ + 6);
return 10000 * hour + 100 * min + sec;
}
private:
static std::mt19937_64 rng;
static std::uniform_int_distribution<T> dist;
T data;
};
template<typename T> std::mt19937_64 RandomWrapper<T>::rng(RandomWrapper<T>::getSeed());
template<typename T> std::uniform_int_distribution<T> RandomWrapper<T>::dist{};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment