32 #ifndef MCKL_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP 33 #define MCKL_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP 42 template <
typename IntType>
44 IntType a, IntType b, std::true_type)
46 constexpr IntType imax = const_one<IntType>() << 32;
48 return a > -imax && b < imax;
51 template <
typename IntType>
53 IntType, IntType b, std::false_type)
55 constexpr IntType imax = const_one<IntType>() << 32;
60 template <
typename IntType>
62 IntType, IntType, std::true_type)
67 template <
typename IntType>
69 IntType a, IntType b, std::false_type)
72 a, b, std::is_signed<IntType>());
75 template <
typename IntType>
79 std::integral_constant<
bool,
80 std::numeric_limits<IntType>::digits <= 32>());
83 template <
typename IntType>
89 template <std::
size_t K,
typename IntType,
typename RNGType>
91 IntType *r, IntType a, IntType b, std::true_type)
94 double ra =
static_cast<double>(a);
95 double rb =
static_cast<double>(b);
96 double *
const u = s.data();
98 muladd(n, u, rb - ra + const_one<double>(), ra, u);
100 for (std::size_t i = 0; i != n; ++i) {
101 r[i] =
static_cast<IntType
>(u[i]);
105 template <std::
size_t,
typename IntType,
typename RNGType>
107 IntType *r, IntType a, IntType b, std::false_type)
109 std::uniform_int_distribution<IntType> uniform(a, b);
110 rand(rng, uniform, n, r);
113 template <std::
size_t K,
typename IntType,
typename RNGType>
115 RNGType &rng, std::size_t n, IntType *r, IntType a, IntType b)
118 std::fill_n(r, n, a);
123 uniform_int_distribution_impl<K>(rng, n, r, a, b, std::true_type()) :
124 uniform_int_distribution_impl<K>(rng, n, r, a, b, std::false_type());
130 UniformInt, uniform_int, IntType, IntType, a, IntType, b)
132 template <
typename IntType>
139 result_type, a, 0, result_type, b,
140 std::numeric_limits<result_type>::max())
151 template <
typename RNGType>
154 using UIntType = std::make_unsigned_t<result_type>;
156 constexpr
result_type imin = std::numeric_limits<result_type>::min();
157 constexpr
result_type imax = std::numeric_limits<result_type>::max();
159 if (param.
a() == param.
b()) {
163 if (param.
a() == imin && param.
b() == imax) {
175 param.
a(), param.
b()) ?
176 generate(rng, param, std::true_type()) :
177 generate(rng, param, std::false_type());
180 template <
typename RNGType>
184 const double ra =
static_cast<double>(param.
a());
185 const double rb =
static_cast<double>(param.
b());
186 const double u = ra + (rb - ra + const_one<double>()) *
u01(rng);
191 template <
typename RNGType>
193 RNGType &rng,
const param_type ¶m, std::false_type)
195 std::uniform_int_distribution<result_type> uniform(
196 param.
a(), param.
b());
206 #endif // MCKL_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP #define MCKL_DEFINE_RANDOM_DISTRIBUTION_2( Name, name, T, T1, p1, v1, T2, p2, v2)
Standard uniform distribution on [0, 1)
#define MCKL_DEFINE_RANDOM_DISTRIBUTION_RAND(Name, T)
RealType u01(UIntType u)
Convert uniform unsigned integers to floating points within [0, 1].
void floor(std::size_t n, const float *a, float *y)
void u01_co_distribution(RNGType &rng, std::size_t n, RealType *r)
bool uniform_int_distribution_check_param(IntType a, IntType b)
void rand(RNGType &rng, ArcsineDistribution< RealType > &distribution, std::size_t N, RealType *r)
#define MCKL_DEFINE_RANDOM_DISTRIBUTION_BATCH_2( Name, name, T, T1, p1, T2, p2)
#define MCKL_ALIGNMENT
The default alignment for scalar type.
#define MCKL_DEFINE_RANDOM_DISTRIBUTION_MEMBER_0
bool uniform_int_distribution_use_double_big(IntType a, IntType b, std::true_type)
bool uniform_int_distribution_use_double(IntType, IntType, std::true_type)
void uniform_int_distribution_impl(RNGType &rng, std::size_t n, IntType *r, IntType a, IntType b, std::true_type)
#define MCKL_DEFINE_RANDOM_DISTRIBUTION_ASSERT_INT_TYPE(Name, MinBits)