32 #ifndef MCKL_RANDOM_INTERNAL_COMMON_HPP 33 #define MCKL_RANDOM_INTERNAL_COMMON_HPP 37 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_ASSERT_REAL_TYPE(Name) \ 38 static_assert(std::is_floating_point<RealType>::value, \ 40 "Distribution** used with RealType other than floating point types"); 42 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_ASSERT_BLAS_TYPE(Name) \ 43 static_assert(::mckl::internal::is_blas_floating_point<RealType>::value, \ 45 "Distribution** used with RealType other than float or double"); 47 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_ASSERT_INT_TYPE(Name, MinBits) \ 48 static_assert(std::is_integral<IntType>::value, \ 50 "Distribution** used with IntType other than integer types"); \ 51 static_assert(CHAR_BIT * sizeof(IntType) >= MinBits, \ 52 "**" #Name "Distribution** used with IntType smaller than " #MinBits \ 55 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_ASSERT_UINT_TYPE(Name, MinBits) \ 56 static_assert(std::is_unsigned<UIntType>::value, \ 58 "Distribution** used with UIntType other than unsigned integer " \ 60 static_assert(std::numeric_limits<UIntType>::digits >= MinBits, \ 61 "**" #Name "Distribution** used with IntType smaller than " #MinBits \ 64 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_ASSERT_REAL_TYPE(Name) \ 65 static_assert(std::is_floating_point<RealType>::value, \ 67 "Distribution** used with RealType other than floating point types"); 69 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_BATCH_0(Name, name, T) \ 70 template <typename T, typename RNGType> \ 71 inline void name##_distribution(RNGType &rng, std::size_t n, T *r) \ 73 const std::size_t K = BufferSize<T>::value; \ 74 const std::size_t M = n / K; \ 75 const std::size_t L = n % K; \ 76 for (std::size_t i = 0; i != M; ++i, r += K) \ 77 ::mckl::internal::name##_distribution_impl<K>(rng, K, r); \ 78 ::mckl::internal::name##_distribution_impl<K>(rng, L, r); \ 81 template <typename T, typename RNGType> \ 82 inline void name##_distribution(RNGType &rng, std::size_t N, T *r, \ 83 const typename Name##Distribution<T>::param_type &) \ 85 name##_distribution(rng, N, r); \ 88 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_BATCH_1(Name, name, T, T1, p1) \ 89 template <typename T, typename RNGType> \ 90 inline void name##_distribution(RNGType &rng, std::size_t N, T *r, T1 p1) \ 92 const std::size_t K = BufferSize<T>::value; \ 93 const std::size_t M = N / K; \ 94 const std::size_t L = N % K; \ 95 for (std::size_t i = 0; i != M; ++i, r += K) \ 96 ::mckl::internal::name##_distribution_impl<K>(rng, K, r, p1); \ 97 ::mckl::internal::name##_distribution_impl<K>(rng, L, r, p1); \ 100 template <typename T, typename RNGType> \ 101 inline void name##_distribution(RNGType &rng, std::size_t N, T *r, \ 102 const typename Name##Distribution<T>::param_type ¶m) \ 104 name##_distribution(rng, N, r, param.p1()); \ 107 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_BATCH_2( \ 108 Name, name, T, T1, p1, T2, p2) \ 109 template <typename T, typename RNGType> \ 110 inline void name##_distribution( \ 111 RNGType &rng, std::size_t N, T *r, T1 p1, T2 p2) \ 113 const std::size_t K = BufferSize<T>::value; \ 114 const std::size_t M = N / K; \ 115 const std::size_t L = N % K; \ 116 for (std::size_t i = 0; i != M; ++i, r += K) \ 117 ::mckl::internal::name##_distribution_impl<K>(rng, K, r, p1, p2); \ 118 ::mckl::internal::name##_distribution_impl<K>(rng, L, r, p1, p2); \ 121 template <typename T, typename RNGType> \ 122 inline void name##_distribution(RNGType &rng, std::size_t N, T *r, \ 123 const typename Name##Distribution<T>::param_type ¶m) \ 125 name##_distribution(rng, N, r, param.p1(), param.p2()); \ 128 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_BATCH_4( \ 129 Name, name, T, T1, p1, T2, p2, T3, p3, T4, p4) \ 130 template <typename T, typename RNGType> \ 131 inline void name##_distribution( \ 132 RNGType &rng, std::size_t N, T *r, T1 p1, T2 p2, T3 p3, T4 p4) \ 134 const std::size_t K = BufferSize<T>::value; \ 135 const std::size_t M = N / K; \ 136 const std::size_t L = N % K; \ 137 for (std::size_t i = 0; i != M; ++i, r += K) { \ 138 ::mckl::internal::name##_distribution_impl<K>( \ 139 rng, K, r, p1, p2, p3, p4); \ 141 ::mckl::internal::name##_distribution_impl<K>( \ 142 rng, L, r, p1, p2, p3, p4); \ 145 template <typename T, typename RNGType> \ 146 inline void name##_distribution(RNGType &rng, std::size_t N, T *r, \ 147 const typename Name##Distribution<T>::param_type ¶m) \ 149 name##_distribution( \ 150 rng, N, r, param.p1(), param.p2(), param.p3(), param.p4()); \ 153 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_PARAM_TYPE_0(Name, T) \ 158 using result_type = T; \ 159 using distribution_type = Name##Distribution<T>; \ 161 friend bool operator==(const param_type &, const param_type &) \ 166 friend bool operator!=(const param_type &, const param_type &) \ 171 template <typename CharT, typename Traits> \ 172 friend std::basic_ostream<CharT, Traits> &operator<<( \ 173 std::basic_ostream<CharT, Traits> &os, const param_type &) \ 178 template <typename CharT, typename Traits> \ 179 friend std::basic_istream<CharT, Traits> &operator>>( \ 180 std::basic_istream<CharT, Traits> &is, param_type &) \ 186 friend distribution_type; \ 187 }; // class param_type 189 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_PARAM_TYPE_1( \ 190 Name, name, T, T1, p1, v1) \ 195 using result_type = T; \ 196 using distribution_type = Name##Distribution<T>; \ 198 explicit param_type(T1 p1 = v1) : p1##_(p1) \ 200 ::mckl::runtime_assert( \ 201 ::mckl::internal::name##_distribution_check_param(p1), \ 203 "Distribution** constructed with invalid arguments"); \ 206 T1 p1() const { return p1##_; } \ 208 friend bool operator==( \ 209 const param_type ¶m1, const param_type ¶m2) \ 211 MCKL_PUSH_CLANG_WARNING("-Wfloat-equal") \ 212 MCKL_PUSH_INTEL_WARNING(1572) \ 213 if (param1.p1##_ != param2.p1##_) \ 216 MCKL_POP_CLANG_WARNING \ 217 MCKL_POP_INTEL_WARNING \ 220 friend bool operator!=( \ 221 const param_type ¶m1, const param_type ¶m2) \ 223 return !(param1 == param2); \ 226 template <typename CharT, typename Traits> \ 227 friend std::basic_ostream<CharT, Traits> &operator<<( \ 228 std::basic_ostream<CharT, Traits> &os, const param_type ¶m) \ 238 template <typename CharT, typename Traits> \ 239 friend std::basic_istream<CharT, Traits> &operator>>( \ 240 std::basic_istream<CharT, Traits> &is, param_type ¶m) \ 246 is >> std::ws >> p1; \ 249 if (::mckl::internal::name##_distribution_check_param(p1)) { \ 252 is.setstate(std::ios_base::failbit); \ 262 friend distribution_type; \ 263 }; // class param_type 265 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_PARAM_TYPE_2( \ 266 Name, name, T, T1, p1, v1, T2, p2, v2) \ 271 using result_type = T; \ 272 using distribution_type = Name##Distribution<T>; \ 274 explicit param_type(T1 p1 = v1, T2 p2 = v2) : p1##_(p1), p2##_(p2) \ 276 ::mckl::runtime_assert( \ 277 ::mckl::internal::name##_distribution_check_param(p1, p2), \ 279 "Distribution** constructed with invalid arguments"); \ 282 T1 p1() const { return p1##_; } \ 283 T2 p2() const { return p2##_; } \ 285 friend bool operator==( \ 286 const param_type ¶m1, const param_type ¶m2) \ 288 MCKL_PUSH_CLANG_WARNING("-Wfloat-equal") \ 289 MCKL_PUSH_INTEL_WARNING(1572) \ 290 if (param1.p1##_ != param2.p1##_) \ 292 if (param1.p2##_ != param2.p2##_) \ 295 MCKL_POP_CLANG_WARNING \ 296 MCKL_POP_INTEL_WARNING \ 299 friend bool operator!=( \ 300 const param_type ¶m1, const param_type ¶m2) \ 302 return !(param1 == param2); \ 305 template <typename CharT, typename Traits> \ 306 friend std::basic_ostream<CharT, Traits> &operator<<( \ 307 std::basic_ostream<CharT, Traits> &os, const param_type ¶m) \ 312 os << param.p1##_ << ' '; \ 318 template <typename CharT, typename Traits> \ 319 friend std::basic_istream<CharT, Traits> &operator>>( \ 320 std::basic_istream<CharT, Traits> &is, param_type ¶m) \ 327 is >> std::ws >> p1; \ 328 is >> std::ws >> p2; \ 331 if (::mckl::internal::name##_distribution_check_param( \ 336 is.setstate(std::ios_base::failbit); \ 347 friend distribution_type; \ 348 }; // class param_type 350 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_PARAM_TYPE_4( \ 351 Name, name, T, T1, p1, v1, T2, p2, v2, T3, p3, v3, T4, p4, v4) \ 356 using result_type = T; \ 357 using distribution_type = Name##Distribution<T>; \ 359 explicit param_type(T1 p1 = v1, T2 p2 = v2, T3 p3 = v3, T4 p4 = v4) \ 360 : p1##_(p1), p2##_(p2), p3##_(p3), p4##_(p4) \ 362 ::mckl::runtime_assert( \ 363 ::mckl::internal::name##_distribution_check_param( \ 366 "Distribution** constructed with invalid arguments"); \ 369 T1 p1() const { return p1##_; } \ 370 T2 p2() const { return p2##_; } \ 371 T3 p3() const { return p3##_; } \ 372 T4 p4() const { return p4##_; } \ 374 friend bool operator==( \ 375 const param_type ¶m1, const param_type ¶m2) \ 377 MCKL_PUSH_CLANG_WARNING("-Wfloat-equal") \ 378 MCKL_PUSH_INTEL_WARNING(1572) \ 379 if (param1.p1##_ != param2.p1##_) \ 381 if (param1.p2##_ != param2.p2##_) \ 383 if (param1.p3##_ != param2.p3##_) \ 385 if (param1.p4##_ != param2.p4##_) \ 388 MCKL_POP_CLANG_WARNING \ 389 MCKL_POP_INTEL_WARNING \ 392 friend bool operator!=( \ 393 const param_type ¶m1, const param_type ¶m2) \ 395 return !(param1 == param2); \ 398 template <typename CharT, typename Traits> \ 399 friend std::basic_ostream<CharT, Traits> &operator<<( \ 400 std::basic_ostream<CharT, Traits> &os, const param_type ¶m) \ 405 os << param.p1##_ << ' '; \ 406 os << param.p2##_ << ' '; \ 407 os << param.p3##_ << ' '; \ 413 template <typename CharT, typename Traits> \ 414 friend std::basic_istream<CharT, Traits> &operator>>( \ 415 std::basic_istream<CharT, Traits> &is, param_type ¶m) \ 424 is >> std::ws >> p1; \ 425 is >> std::ws >> p2; \ 426 is >> std::ws >> p3; \ 427 is >> std::ws >> p4; \ 430 if (::mckl::internal::name##_distribution_check_param( \ 437 is.setstate(std::ios_base::failbit); \ 450 friend distribution_type; \ 451 }; // class param_type 453 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_CONSTRUCTOR_0(Name, T) \ 455 using result_type = T; \ 456 using distribution_type = Name##Distribution<T>; \ 458 Name##Distribution() = default; \ 459 explicit Name##Distribution(const param_type &) { reset(); } \ 460 explicit Name##Distribution(param_type &&) { reset(); } 462 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_CONSTRUCTOR_1(Name, T, T1, p1, v1) \ 464 using result_type = T; \ 465 using distribution_type = Name##Distribution<T>; \ 467 explicit Name##Distribution(T1 p1 = v1) : param_(p1) { reset(); } \ 469 explicit Name##Distribution(const param_type ¶m) : param_(param) \ 474 explicit Name##Distribution(param_type &¶m) \ 475 : param_(std::move(param)) \ 480 T1 p1() const { return param_.p1(); } 482 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_CONSTRUCTOR_2( \ 483 Name, T, T1, p1, v1, T2, p2, v2) \ 485 using result_type = T; \ 486 using distribution_type = Name##Distribution<T>; \ 488 explicit Name##Distribution(T1 p1 = v1, T2 p2 = v2) : param_(p1, p2) \ 493 explicit Name##Distribution(const param_type ¶m) : param_(param) \ 498 explicit Name##Distribution(param_type &¶m) \ 499 : param_(std::move(param)) \ 504 T1 p1() const { return param_.p1(); } \ 505 T2 p2() const { return param_.p2(); } 507 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_CONSTRUCTOR_4( \ 508 Name, T, T1, p1, v1, T2, p2, v2, T3, p3, v3, T4, p4, v4) \ 510 using result_type = T; \ 511 using distribution_type = Name##Distribution<T>; \ 513 explicit Name##Distribution( \ 514 T1 p1 = v1, T2 p2 = v2, T3 p3 = v3, T4 p4 = v4) \ 515 : param_(p1, p2, p3, p4) \ 520 explicit Name##Distribution(const param_type ¶m) : param_(param) \ 525 explicit Name##Distribution(param_type &¶m) \ 526 : param_(std::move(param)) \ 531 T1 p1() const { return param_.p1(); } \ 532 T2 p2() const { return param_.p2(); } \ 533 T3 p3() const { return param_.p3(); } \ 534 T4 p4() const { return param_.p4(); } 536 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_MEMBER_0 \ 538 bool is_equal(const distribution_type &) const { return true; } \ 540 template <typename CharT, typename Traits> \ 541 void ostream(std::basic_ostream<CharT, Traits> &) const \ 545 template <typename CharT, typename Traits> \ 546 void istream(std::basic_istream<CharT, Traits> &) \ 550 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_MEMBER_1(T1, m1) \ 554 bool is_equal(const distribution_type &other) const \ 556 if (m1 != other.m1) \ 561 template <typename CharT, typename Traits> \ 562 void ostream(std::basic_ostream<CharT, Traits> &os) const \ 570 template <typename CharT, typename Traits> \ 571 void istream(std::basic_istream<CharT, Traits> &is) \ 577 is >> std::ws >> tmp1; \ 579 m1 = std::move(tmp1); \ 583 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_MEMBER_2(T1, m1, T2, m2) \ 588 bool is_equal(const distribution_type &other) const \ 590 if (m1 != other.m1) \ 592 if (m2 != other.m2) \ 597 template <typename CharT, typename Traits> \ 598 void ostream(std::basic_ostream<CharT, Traits> &os) const \ 607 template <typename CharT, typename Traits> \ 608 void istream(std::basic_istream<CharT, Traits> &is) \ 615 is >> std::ws >> tmp1; \ 616 is >> std::ws >> tmp2; \ 618 m1 = std::move(tmp1); \ 619 m2 = std::move(tmp2); \ 623 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_OPERATOR(Name, name) \ 625 const param_type ¶m() const { return param_; } \ 627 void param(const param_type ¶m) \ 633 void param(param_type &¶m) \ 635 param_ = std::move(param); \ 639 template <typename RNGType> \ 640 result_type operator()(RNGType &rng) \ 642 return operator()(rng, param_); \ 645 template <typename RNGType> \ 646 result_type operator()(RNGType &rng, const param_type ¶m) \ 648 return generate(rng, param); \ 651 template <typename RNGType> \ 652 void operator()(RNGType &rng, std::size_t n, result_type *r) \ 654 operator()(rng, n, r, param_); \ 657 template <typename RNGType> \ 659 RNGType &rng, std::size_t n, result_type *r, const param_type ¶m) \ 661 name##_distribution(rng, n, r, param); \ 664 friend bool operator==( \ 665 const distribution_type &dist1, const distribution_type &dist2) \ 667 return dist1.param_ == dist2.param_ && dist1.is_equal(dist2); \ 670 friend bool operator!=( \ 671 const distribution_type &dist1, const distribution_type &dist2) \ 673 return !(dist1 == dist2); \ 676 template <typename CharT, typename Traits> \ 677 friend std::basic_ostream<CharT, Traits> &operator<<( \ 678 std::basic_ostream<CharT, Traits> &os, const distribution_type &dist) \ 689 template <typename CharT, typename Traits> \ 690 friend std::basic_istream<CharT, Traits> &operator>>( \ 691 std::basic_istream<CharT, Traits> &is, distribution_type &dist) \ 696 is >> std::ws >> dist.param_; \ 706 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_RAND(Name, T) \ 707 template <typename T, typename RNGType> \ 708 inline void rand(RNGType &rng, Name##Distribution<T> &distribution, \ 709 std::size_t N, T *r) \ 711 distribution(rng, N, r); \ 714 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_0(Name, name, T) \ 715 MCKL_DEFINE_RANDOM_DISTRIBUTION_PARAM_TYPE_0(Name, T) \ 716 MCKL_DEFINE_RANDOM_DISTRIBUTION_CONSTRUCTOR_0(Name, T) \ 717 MCKL_DEFINE_RANDOM_DISTRIBUTION_OPERATOR(Name, name) 719 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_1(Name, name, T, T1, p1, v1) \ 720 MCKL_DEFINE_RANDOM_DISTRIBUTION_PARAM_TYPE_1(Name, name, T, T1, p1, v1) \ 721 MCKL_DEFINE_RANDOM_DISTRIBUTION_CONSTRUCTOR_1(Name, T, T1, p1, v1) \ 722 MCKL_DEFINE_RANDOM_DISTRIBUTION_OPERATOR(Name, name) 724 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_2( \ 725 Name, name, T, T1, p1, v1, T2, p2, v2) \ 726 MCKL_DEFINE_RANDOM_DISTRIBUTION_PARAM_TYPE_2( \ 727 Name, name, T, T1, p1, v1, T2, p2, v2) \ 728 MCKL_DEFINE_RANDOM_DISTRIBUTION_CONSTRUCTOR_2( \ 729 Name, T, T1, p1, v1, T2, p2, v2) \ 730 MCKL_DEFINE_RANDOM_DISTRIBUTION_OPERATOR(Name, name) 732 #define MCKL_DEFINE_RANDOM_DISTRIBUTION_4( \ 733 Name, name, T, T1, p1, v1, T2, p2, v2, T3, p3, v3, T4, p4, v4) \ 734 MCKL_DEFINE_RANDOM_DISTRIBUTION_PARAM_TYPE_4( \ 735 Name, name, T, T1, p1, v1, T2, p2, v2, T3, p3, v3, T4, p4, v4) \ 736 MCKL_DEFINE_RANDOM_DISTRIBUTION_CONSTRUCTOR_4( \ 737 Name, T, T1, p1, v1, T2, p2, v2, T3, p3, v3, T4, p4, v4) \ 738 MCKL_DEFINE_RANDOM_DISTRIBUTION_OPERATOR(Name, name) 740 #define MCKL_DEFINE_RANDOM_TEST_OPERATOR(ResultType) \ 741 template <typename DistributionType> \ 742 ResultType operator()(DistributionType &&distribution) \ 744 ::mckl::internal::DummyRNG rng; \ 745 ::mckl::internal::DummyDistribution<DistributionType> dist( \ 748 return operator()(rng, dist); \ 759 template <
typename DistributionType>
766 : distribution_(distribution)
770 template <
typename RNGType>
773 return distribution_();
777 DistributionType distribution_;
780 template <std::
size_t N, std::
size_t D, std::
size_t T>
786 template <std::
size_t N, std::
size_t D, std::
size_t T>
789 return Pow<std::size_t, D, T - 1 - N>::value * s[N] +
790 serial_index<N + 1, D, T>(
791 s, std::integral_constant<bool, N + 1 < T>());
794 template <std::
size_t D, std::
size_t T,
typename ResultType>
797 std::array<std::size_t, T> s;
798 for (std::size_t i = 0; i != T; ++i) {
799 s[i] = std::min(static_cast<std::size_t>(r[i]), D - 1);
802 return serial_index<0, D, T>(
803 s.data(), std::integral_constant<bool, 0 < T>());
806 template <std::
size_t N,
typename ResultType>
811 for (std::size_t i = 1; i < N; ++i) {
821 template <std::
size_t N,
typename ResultType>
826 template <std::
size_t N,
typename ResultType>
829 std::size_t s = permutation_imax<N>(r);
835 template <std::
size_t T,
typename ResultType>
839 permutation_sort<T>(r, f, std::integral_constant<bool, 1 < T>());
849 std::size_t K = np_all.size();
859 if (np_all[kmin] >= npmin) {
865 while (kmax < K && np_all[kmax] >= npmin) {
873 np.reserve(kmax - kmin + 1);
881 np.push_back(np_all[k]);
884 np.back() += n - std::accumulate(np.begin(), np.end(), 0.0);
887 template <
typename IntType, IntType D,
typename RealType>
888 inline IntType
ftoi(RealType r)
890 std::size_t u =
static_cast<IntType
>(r);
891 u = u < D ? u : D - 1;
896 template <
typename IntType,
typename RealType>
897 inline IntType
ftoi(RealType x, std::true_type)
899 constexpr RealType maxval =
900 static_cast<RealType
>(std::numeric_limits<IntType>::max());
902 return static_cast<IntType
>(std::min(maxval, x));
905 template <
typename IntType,
typename RealType>
906 inline IntType
ftoi(RealType x, std::false_type)
908 constexpr RealType maxval =
909 static_cast<RealType
>(std::numeric_limits<IntType>::max() / 2);
911 return static_cast<IntType
>(std::min(maxval, x));
914 template <
typename IntType,
typename RealType>
915 inline IntType
ftoi(RealType x)
917 constexpr
int W = std::numeric_limits<IntType>::digits;
918 constexpr
int M = std::numeric_limits<RealType>::digits;
920 return ftoi<IntType>(x, std::integral_constant<bool, W <= M>());
923 template <
typename T, std::size_t, std::size_t,
924 int = std::numeric_limits<T>::digits>
927 template <
typename T, std::size_t, std::size_t,
928 int = std::numeric_limits<T>::digits>
931 template <
typename T, std::size_t, std::size_t,
932 int = std::numeric_limits<T>::digits>
939 template <
typename RNGType>
942 using result_type =
typename RNGType::result_type;
944 static constexpr
typename RNGType::result_type R_ = RNGType::min() == 0 &&
945 RNGType::max() == std::numeric_limits<result_type>::max() ?
947 RNGType::max() - RNGType::min() + const_one<result_type>();
952 static constexpr
bool is_full_range =
953 RNGType::min() == 0 && (R_ & (R_ - 1)) == 0;
968 template <
typename RNGType>
969 inline typename RNGType::result_type
rand(RNGType &rng)
976 template <
typename RNGType>
977 inline void rand(RNGType &rng, std::size_t n,
typename RNGType::result_type *r)
979 for (std::size_t i = 0; i != n; ++i) {
986 template <
typename RNGType,
typename DistributionType>
987 inline typename DistributionType::result_type
rand(
988 RNGType &rng, DistributionType &distribution)
990 return distribution(rng);
995 template <
typename RNGType,
typename DistributionType>
996 inline void rand(RNGType &rng, DistributionType &distribution, std::size_t n,
997 typename DistributionType::result_type *r)
999 for (std::size_t i = 0; i != n; ++i) {
1000 r[i] = distribution(rng);
1011 template <
typename RNGType>
1014 template <
typename =
double>
1017 template <
typename =
double>
1020 template <
typename =
double>
1023 template <
typename =
double>
1026 template <
typename =
double>
1029 template <
typename =
double>
1032 template <
typename =
double>
1035 template <
typename =
double>
1038 template <
typename =
double>
1041 template <
typename =
double>
1044 template <
typename =
double>
1047 template <
typename =
double>
1050 template <
typename =
double>
1053 template <
typename =
double>
1056 template <
typename =
double>
1059 template <
typename =
double>
1062 template <
typename =
double>
1065 template <
typename =
double>
1068 template <
typename =
double>
1071 template <
typename =
double>
1074 template <
typename =
double>
1077 template <
typename =
double>
1080 template <
typename =
double>
1083 template <
typename =
double>
1086 template <
typename =
unsigned>
1089 template <
typename =
double>
1092 template <
typename =
double>
1095 template <
typename =
bool>
1098 template <
typename =
int>
1101 template <
typename =
int>
1104 template <
typename =
int>
1107 template <
typename =
int>
1112 #endif // MCKL_RANDOM_INTERNAL_COMMON_HPP Multivariate Normal distribution.
Standard uniform distribution on [0, 1)
Drawing a subset without replacement.
std::size_t permutation_imax(ResultType *r)
std::size_t permutation_index(ResultType *r)
void group_np(double n, const Vector< double > &np_all, Vector< double > &np, std::size_t &kmin, std::size_t &kmax)
std::vector< T, Alloc > Vector
std::vector with Allocator as the default allocator
Standard uniform distribution on (0, 1].
std::size_t serial_index(const std::size_t *, std::false_type)
Standard uniform distribution on (0, 1)
double operator()(RNGType &)
Extreme value distribution.
Exponential distribution.
void rand(RNGType &rng, ArcsineDistribution< RealType > &distribution, std::size_t N, RealType *r)
Standard uniform distribution on [0, 1)
void permutation_sort(ResultType *, std::size_t &, std::false_type)
Draw a single sample given weights.
Standard uniform distribution on [0, 1].
DummyDistribution(const DistributionType &distribution)
typename SeedTrait< RNGType >::type SeedType