Last active
August 20, 2019 09:17
-
-
Save IMelker/b13d29a3c90d0ac29f5673a51b32f623 to your computer and use it in GitHub Desktop.
RandomWrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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