39 using result_type = std::random_device::result_type;
40 using pseudo_engine = std::mt19937_64;
48 sizeof(result_type) == 2 ||
49 sizeof(result_type) == 4 ||
50 sizeof(result_type) == 8,
51 "result_type must be 16, 32 or 64 bits");
55 result_type operator()();
57 static constexpr result_type min() {
58 return std::numeric_limits<result_type>::lowest();
61 static constexpr result_type max() {
62 return std::numeric_limits<result_type>::max();
65 double entropy()
const {
66 if (hasRdrand() or hasRdseed())
71 static bool hasRdrand() {
72 static const bool hasrdrand = _hasRdrand();
76 static bool hasRdseed() {
77 static const bool hasrdseed = _hasRdseed();
82 random_device& operator=(random_device&) =
delete;
85 std::uniform_int_distribution<result_type> dis {};
87 static bool hasIntelCpu();
88 static bool _hasRdrand();
89 static bool _hasRdseed();
96 CPUIDinfo(
const unsigned int func,
const unsigned int subfunc);
98 bool rdrandStep(result_type* r);
99 bool rdrand(result_type* r);
100 bool rdseedStep(result_type* r);
101 bool rdseed(result_type* r);
106using random_device = std::random_device;
110using random_device = std::random_device;
113template<
class T = std::mt19937, std::
size_t N = T::state_size>
114auto getSeededRandomEngine () ->
typename std::enable_if<!!N, T>::type {
115 typename T::result_type random_data[N];
116 for (
unsigned i=0; i<256; i++) {
118 random_device source;
119 std::generate(std::begin(random_data), std::end(random_data), std::ref(source));
120 std::seed_seq seeds(std::begin(random_data), std::end(random_data));
121 T seededEngine (seeds);
124 std::this_thread::sleep_for(std::chrono::milliseconds(1));
127 throw std::runtime_error(
"Can't seed random engine");