32 #ifndef VSMC_RNG_UNIFORM_BITS_DISTRIBUTION_HPP 33 #define VSMC_RNG_UNIFORM_BITS_DISTRIBUTION_HPP 43 template <
typename UIntType,
int Bits>
47 template <
typename RNGType>
48 static UIntType
eval(RNGType &rng)
56 template <
typename RNGType>
57 static UIntType
eval(RNGType &rng, std::true_type, std::true_type)
59 return static_cast<UIntType
>(rng());
62 template <
typename RNGType>
63 static UIntType
eval(RNGType &rng, std::false_type, std::true_type)
68 template <
typename RNGType>
69 static UIntType
eval(RNGType &rng, std::true_type, std::false_type)
71 return static_cast<UIntType
>(
73 rng, std::true_type()));
76 template <
typename RNGType>
77 static UIntType
eval(RNGType &rng, std::false_type, std::false_type)
79 return eval(rng, std::true_type(), std::false_type());
82 template <
int,
int,
int,
typename RNGType>
83 static UIntType patch(RNGType &, std::false_type)
88 template <
int N,
int B,
int R,
typename RNGType>
89 static UIntType patch(RNGType &rng, std::true_type)
91 return static_cast<UIntType
>((rng() >> R) << (B * N)) +
93 rng, std::integral_constant<
bool, (N * B + B) < Bits>());
101 template <
typename UIntType>
124 template <
typename CharT,
typename Traits>
126 std::basic_ostream<CharT, Traits> &os,
const param_type &)
131 template <
typename CharT,
typename Traits>
133 std::basic_istream<CharT, Traits> &is,
param_type &)
144 return std::numeric_limits<result_type>::min
VSMC_MNE();
149 return std::numeric_limits<result_type>::max
VSMC_MNE();
154 template <
typename RNGType>
161 template <
typename RNGType>
164 return operator()(rng);
167 template <
typename RNGType>
173 template <
typename RNGType>
192 template <
typename CharT,
typename Traits>
194 std::basic_ostream<CharT, Traits> &os,
200 template <
typename CharT,
typename Traits>
202 std::basic_istream<CharT, Traits> &is,
212 template <
typename UIntType,
typename RNGType,
bool B1,
bool B2>
214 UIntType *r, std::false_type, std::integral_constant<bool, B1>,
215 std::integral_constant<bool, B2>)
217 for (std::size_t i = 0; i != n; ++i)
221 template <
typename UIntType,
typename RNGType>
223 UIntType *r, std::true_type, std::true_type, std::true_type)
225 rng_rand(rng, n, reinterpret_cast<typename RNGType::result_type *>(r));
228 template <
typename UIntType,
typename RNGType>
230 UIntType *r, std::true_type, std::true_type, std::false_type)
232 const std::size_t k =
233 sizeof(
typename RNGType::result_type) /
sizeof(UIntType);
234 const std::size_t m = n / k;
235 const std::size_t l = n % k;
236 rng_rand(rng, m, reinterpret_cast<typename RNGType::result_type *>(r));
239 for (std::size_t i = 0; i != l; ++i)
243 template <
typename UIntType,
typename RNGType>
245 UIntType *r, std::true_type, std::false_type, std::true_type)
247 const std::size_t k =
248 sizeof(UIntType) /
sizeof(
typename RNGType::result_type);
249 const std::size_t m = n * k;
250 rng_rand(rng, m, reinterpret_cast<typename RNGType::result_type *>(r));
253 template <
typename UIntType,
typename RNGType>
255 UIntType *r, std::true_type, std::false_type, std::false_type)
257 for (std::size_t i = 0; i != n; ++i)
263 template <
typename UIntType,
typename RNGType>
270 std::integral_constant<bool, mbits == 0>(),
271 std::integral_constant <
bool,
272 rbits >= ubits && rbits % ubits == 0 > (),
273 std::integral_constant <
bool,
274 ubits >= rbits && ubits % rbits == 0 > ());
277 template <
typename UIntType,
typename RNGType>
279 std::size_t n, UIntType *r)
286 #endif // VSMC_RNG_UNIFORM_BITS_DISTRIBUTION_HPP
void rng_rand(RNGType &rng, BernoulliDistribution< IntType > &dist, std::size_t n, IntType *r)
void uniform_bits_distribution_impl(RNGType &rng, std::size_t n, UIntType *r, std::false_type, std::integral_constant< bool, B1 >, std::integral_constant< bool, B2 >)
void uniform_bits_distribution(RNGType &, std::size_t, UIntType *)