32 #ifndef __MicroURNG_dot_hpp__ 33 #define __MicroURNG_dot_hpp__ 78 template <
typename CBRNG>
86 typedef CBRNG cbrng_type;
87 static const int BITS = 32;
88 typedef typename cbrng_type::ctr_type ctr_type;
89 typedef typename cbrng_type::key_type key_type;
90 typedef typename cbrng_type::ukey_type ukey_type;
91 typedef typename ctr_type::value_type result_type;
93 RANDOM_ITERATOR_R123_STATIC_ASSERT(std::numeric_limits<result_type>::digits >= BITS,
94 "The result_type must have at least 32 bits");
96 result_type operator()() {
99 const size_t W = std::numeric_limits<result_type>::digits;
101 c[c0.size() - 1] |= n << (W - BITS);
104 last_elem = rdata.size();
106 return rdata[--last_elem];
108 MicroURNG(cbrng_type _b, ctr_type _c0, ukey_type _uk)
127 const static result_type _Min = 0;
128 const static result_type _Max = ~((result_type)0);
130 static RANDOM_ITERATOR_R123_CONSTEXPR result_type min
131 RANDOM_ITERATOR_R123_NO_MACRO_SUBST() {
134 static RANDOM_ITERATOR_R123_CONSTEXPR result_type max
135 RANDOM_ITERATOR_R123_NO_MACRO_SUBST() {
139 const ctr_type& counter()
const {
return c0; }
140 void reset(ctr_type _c0, ukey_type _uk) {
152 RANDOM_ITERATOR_R123_ULONG_LONG n;
156 result_type r = c0[c0.size() - 1];
157 result_type mask = ((uint64_t)std::numeric_limits<result_type>::max
158 RANDOM_ITERATOR_R123_NO_MACRO_SUBST()) >>
161 throw std::runtime_error(
"MicroURNG: c0, does not have high bits clear");
Given a CBRNG whose ctr_type has an unsigned integral value_type, MicroURNG<CBRNG>(c, k) is a type that satisfies the requirements of a C++11 Uniform Random Number Generator.