From 3879666b02d38ffbdaf6add7baeda1041b68a075 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Thu, 16 Jan 2014 01:04:31 +0900 Subject: [PATCH] fix random generation implementation --- sprout/algorithm/fixed/random_swap.hpp | 7 ++-- sprout/algorithm/fixed/random_swap_result.hpp | 9 ++-- sprout/algorithm/fixed/shuffle.hpp | 7 ++-- sprout/algorithm/fixed/shuffle_result.hpp | 9 ++-- sprout/random/additive_combine.hpp | 9 ++-- sprout/random/bernoulli_distribution.hpp | 7 +++- sprout/random/binomial_distribution.hpp | 33 +++++++++------ sprout/random/detail/uniform_int_float.hpp | 7 ++-- sprout/random/geometric_distribution.hpp | 5 ++- sprout/random/linear_congruential.hpp | 9 ++-- sprout/random/normal_distribution.hpp | 7 ++-- sprout/random/shuffle_order.hpp | 41 ++++++++++--------- sprout/random/uniform_01.hpp | 9 ++-- sprout/random/uniform_int_distribution.hpp | 33 +++++++-------- sprout/random/uniform_real_distribution.hpp | 23 ++++++----- sprout/random/uniform_smallint.hpp | 21 +++++----- sprout/random/xor_combine.hpp | 9 ++-- sprout/uuid/random_generator.hpp | 5 ++- 18 files changed, 140 insertions(+), 110 deletions(-) diff --git a/sprout/algorithm/fixed/random_swap.hpp b/sprout/algorithm/fixed/random_swap.hpp index 37fcc2e9..312b02bf 100644 --- a/sprout/algorithm/fixed/random_swap.hpp +++ b/sprout/algorithm/fixed/random_swap.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include namespace sprout { @@ -26,14 +27,14 @@ namespace sprout { template inline SPROUT_CONSTEXPR sprout::array make_random_swap_indexes_2(Random const& rnd, std::ptrdiff_t i0) { - return sprout::array{{i0, rnd.result()}}; + return sprout::array{{i0, sprout::generators::generated_value(rnd)}}; } template inline SPROUT_CONSTEXPR sprout::array make_random_swap_indexes_1(Random const& rnd) { return sprout::fixed::detail::make_random_swap_indexes_2( - rnd(), - rnd.result() + sprout::generators::next_generator(rnd)(), + sprout::generators::generated_value(rnd) ); } template diff --git a/sprout/algorithm/fixed/random_swap_result.hpp b/sprout/algorithm/fixed/random_swap_result.hpp index cc5dcd7e..7d6627a9 100644 --- a/sprout/algorithm/fixed/random_swap_result.hpp +++ b/sprout/algorithm/fixed/random_swap_result.hpp @@ -22,6 +22,7 @@ #include #include #include +#include #include namespace sprout { @@ -32,16 +33,16 @@ namespace sprout { make_random_swap_result_indexes_2(Random const& rnd, std::ptrdiff_t i0) { typedef sprout::pair, typename std::decay::type> result_type; return result_type( - sprout::array{{i0, rnd.result()}}, - rnd.engine() + sprout::array{{i0, sprout::generators::generated_value(rnd)}}, + sprout::generators::next_generator(rnd).engine() ); } template inline SPROUT_CONSTEXPR sprout::pair, typename std::decay::type> make_random_swap_result_indexes_1(Random const& rnd) { return sprout::fixed::detail::make_random_swap_result_indexes_2( - rnd(), - rnd.result() + sprout::generators::next_generator(rnd)(), + sprout::generators::generated_value(rnd) ); } template diff --git a/sprout/algorithm/fixed/shuffle.hpp b/sprout/algorithm/fixed/shuffle.hpp index f230ec51..d2c54954 100644 --- a/sprout/algorithm/fixed/shuffle.hpp +++ b/sprout/algorithm/fixed/shuffle.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include namespace sprout { @@ -32,11 +33,11 @@ namespace sprout { return i < n - 1 ? sprout::fixed::detail::make_shuffle_indexes_1( n, - rnd(), - sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + rnd.result()), + sprout::generators::next_generator(rnd)(), + sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + sprout::generators::generated_value(rnd)), i + 1 ) - : sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + rnd.result()) + : sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + sprout::generators::generated_value(rnd)) ; } template diff --git a/sprout/algorithm/fixed/shuffle_result.hpp b/sprout/algorithm/fixed/shuffle_result.hpp index 7c44e95a..6b9363be 100644 --- a/sprout/algorithm/fixed/shuffle_result.hpp +++ b/sprout/algorithm/fixed/shuffle_result.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #include namespace sprout { @@ -36,13 +37,13 @@ namespace sprout { return i < n - 1 ? sprout::fixed::detail::make_shuffle_result_indexes_1( n, - rnd(), - sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + rnd.result()), + sprout::generators::next_generator(rnd)(), + sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + sprout::generators::generated_value(rnd)), i + 1 ) : result_type( - sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + rnd.result()), - rnd.engine() + sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + sprout::generators::generated_value(rnd)), + sprout::generators::next_generator(rnd).engine() ) ; } diff --git a/sprout/random/additive_combine.hpp b/sprout/random/additive_combine.hpp index 18f603e4..e9f9910f 100644 --- a/sprout/random/additive_combine.hpp +++ b/sprout/random/additive_combine.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include namespace sprout { @@ -52,12 +53,12 @@ namespace sprout { template SPROUT_CONSTEXPR sprout::random::random_result generate(Random1 const& rnd1, Random2 const& rnd2) const { return sprout::random::random_result( - rnd2.result() < rnd1.result() - ? rnd1.result() - rnd2.result() - : rnd1.result() - rnd2.result() + base1_type::modulus - 1 + sprout::generators::generated_value(rnd2) < sprout::generators::generated_value(rnd1) + ? sprout::generators::generated_value(rnd1) - sprout::generators::generated_value(rnd2) + : sprout::generators::generated_value(rnd1) - sprout::generators::generated_value(rnd2) + base1_type::modulus - 1 , additive_combine_engine( - rnd1.engine(), rnd2.engine(), + sprout::generators::next_generator(rnd1), sprout::generators::next_generator(rnd2), private_construct_t() ) ); diff --git a/sprout/random/bernoulli_distribution.hpp b/sprout/random/bernoulli_distribution.hpp index 25035855..7d9ec82e 100644 --- a/sprout/random/bernoulli_distribution.hpp +++ b/sprout/random/bernoulli_distribution.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace sprout { @@ -82,8 +83,10 @@ namespace sprout { ) const { return sprout::random::random_result( - RealType(rnd.result() - rnd.engine().min()) <= p_ * RealType(rnd.engine().max() - rnd.engine().min()), - rnd.engine(), + RealType(sprout::generators::generated_value(rnd) - sprout::generators::next_generator(rnd).min()) + <= p_ * RealType(sprout::generators::next_generator(rnd).max() - sprout::generators::next_generator(rnd).min()) + , + sprout::generators::next_generator(rnd), *this ); } diff --git a/sprout/random/binomial_distribution.hpp b/sprout/random/binomial_distribution.hpp index 3235b5dd..43ee5905 100644 --- a/sprout/random/binomial_distribution.hpp +++ b/sprout/random/binomial_distribution.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #ifdef SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE # include @@ -320,7 +321,7 @@ namespace sprout { template SPROUT_CONSTEXPR sprout::random::random_result invert_0(IntType t, RealType p, Random const& rnd) const { - return invert_1(t, p, rnd.engine(), rnd.result()); + return invert_1(t, p, sprout::generators::next_generator(rnd).engine(), sprout::generators::generated_value(rnd)); } template SPROUT_CONSTEXPR sprout::random::random_result @@ -330,7 +331,11 @@ namespace sprout { template SPROUT_CONSTEXPR sprout::random::random_result invert2_0(IntType t, sprout::random::random_result const& rnd) const { - return sprout::random::random_result(t - rnd.result(), rnd.engine(), rnd.distribution()); + return sprout::random::random_result( + t - sprout::generators::generated_value(rnd), + sprout::generators::next_generator(rnd).engine(), + sprout::generators::next_generator(rnd).distribution() + ); } template SPROUT_CONSTEXPR sprout::random::random_result @@ -483,11 +488,11 @@ namespace sprout { generate_2(Random const& rnd, RealType v) const { return v >= btrd_.v_r ? generate_3( - rnd.engine(), v, - rnd.result() - RealType(0.5) + sprout::generators::next_generator(rnd).engine(), v, + sprout::generators::generated_value(rnd) - RealType(0.5) ) : generate_3( - rnd.engine(), rnd.result() * btrd_.v_r, + sprout::generators::next_generator(rnd).engine(), sprout::generators::generated_value(rnd) * btrd_.v_r, ((v / btrd_.v_r - RealType(0.93)) < 0 ? RealType(-0.5) : RealType(0.5)) - (v / btrd_.v_r - RealType(0.93)) ) ; @@ -526,7 +531,7 @@ namespace sprout { template SPROUT_CONSTEXPR sprout::random::random_result generate_0(Random const& rnd) const { - return generate_1(rnd.engine(), rnd.result()); + return generate_1(sprout::generators::next_generator(rnd).engine(), sprout::generators::generated_value(rnd)); } template SPROUT_CONSTEXPR sprout::random::random_result @@ -634,13 +639,13 @@ namespace sprout { generate_2(Random const& rnd, RealType v) const { return v >= btrd_.v_r ? generate_3( - rnd.engine(), + sprout::generators::next_generator(rnd).engine(), v, - rnd.result() - RealType(0.5) + sprout::generators::generated_value(rnd) - RealType(0.5) ) : generate_3( - rnd.engine(), - rnd.result() * btrd_.v_r, + sprout::generators::next_generator(rnd).engine(), + sprout::generators::generated_value(rnd) * btrd_.v_r, ((v / btrd_.v_r - RealType(0.93)) < 0 ? RealType(-0.5) : RealType(0.5)) - (v / btrd_.v_r - RealType(0.93)) ) ; @@ -665,7 +670,7 @@ namespace sprout { template SPROUT_CONSTEXPR sprout::random::random_result generate_0(Random const& rnd) const { - return generate_1(rnd.engine(), rnd.result()); + return generate_1(sprout::generators::next_generator(rnd).engine(), sprout::generators::generated_value(rnd)); } template SPROUT_CONSTEXPR sprout::random::random_result @@ -676,7 +681,11 @@ namespace sprout { template SPROUT_CONSTEXPR sprout::random::random_result generate2_0(IntType t, sprout::random::random_result const& rnd) const { - return sprout::random::random_result(t - rnd.result(), rnd.engine(), rnd.distribution()); + return sprout::random::random_result( + t - sprout::generators::generated_value(rnd), + sprout::generators::next_generator(rnd).engine(), + sprout::generators::next_generator(rnd).distribution() + ); } template SPROUT_CONSTEXPR sprout::random::random_result diff --git a/sprout/random/detail/uniform_int_float.hpp b/sprout/random/detail/uniform_int_float.hpp index 8fccd202..02b10046 100644 --- a/sprout/random/detail/uniform_int_float.hpp +++ b/sprout/random/detail/uniform_int_float.hpp @@ -14,13 +14,14 @@ #include #include #include +#include #include #include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT namespace sprout { namespace random { namespace detail { - template + template class uniform_int_float { public: typedef URNG base_type; @@ -38,8 +39,8 @@ namespace sprout { ) const { return sprout::random::random_result( - static_cast(rnd.result() * (static_cast(max()) + 1)), - uniform_int_float(rnd.engine()) + static_cast(sprout::generators::generated_value(rnd) * (static_cast(max()) + 1)), + uniform_int_float(sprout::generators::next_generator(rnd)) ); } public: diff --git a/sprout/random/geometric_distribution.hpp b/sprout/random/geometric_distribution.hpp index e99ab080..2ef9a86c 100644 --- a/sprout/random/geometric_distribution.hpp +++ b/sprout/random/geometric_distribution.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include namespace sprout { @@ -90,8 +91,8 @@ namespace sprout { template SPROUT_CONSTEXPR sprout::random::random_result generate_1(Random const& rnd) const { return sprout::random::random_result( - static_cast(sprout::math::floor(sprout::math::log(RealType(1) - rnd.result()) / log_1mp_)), - rnd.engine(), + static_cast(sprout::math::floor(sprout::math::log(RealType(1) - sprout::generators::generated_value(rnd)) / log_1mp_)), + sprout::generators::next_generator(rnd).engine(), *this ); } diff --git a/sprout/random/linear_congruential.hpp b/sprout/random/linear_congruential.hpp index 1055e7fe..54a635d1 100644 --- a/sprout/random/linear_congruential.hpp +++ b/sprout/random/linear_congruential.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -208,11 +209,11 @@ namespace sprout { SPROUT_CONSTEXPR rand48(lcf_type const& lcf, private_construct_t) : lcf_(lcf) {} - template - SPROUT_CONSTEXPR sprout::random::random_result generate(LcfResult const& lcf_result) const { + template + SPROUT_CONSTEXPR sprout::random::random_result generate(EngineResult const& rnd) const { return sprout::random::random_result( - static_cast(lcf_result.result()) >> 17, - rand48(lcf_result.engine(), private_construct_t()) + static_cast(sprout::generators::generated_value(rnd)) >> 17, + rand48(sprout::generators::next_generator(rnd), private_construct_t()) ); } public: diff --git a/sprout/random/normal_distribution.hpp b/sprout/random/normal_distribution.hpp index e35acec6..c6fb062e 100644 --- a/sprout/random/normal_distribution.hpp +++ b/sprout/random/normal_distribution.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include namespace sprout { @@ -140,14 +141,14 @@ namespace sprout { SPROUT_CONSTEXPR sprout::random::random_result generate_1_1(RealType r1, Random const& rnd) const { return generate_2( - rnd.engine(), r1, rnd.result(), - sprout::sqrt(-result_type(2) * sprout::math::log(result_type(1) - rnd.result())), true + sprout::generators::next_generator(rnd).engine(), r1, sprout::generators::generated_value(rnd), + sprout::sqrt(-result_type(2) * sprout::math::log(result_type(1) - sprout::generators::generated_value(rnd))), true ); } template SPROUT_CONSTEXPR sprout::random::random_result generate_1(Random const& rnd) const { - return generate_1_1(rnd.result(), rnd()); + return generate_1_1(sprout::generators::generated_value(rnd), sprout::generators::next_generator(rnd)()); } template SPROUT_CONSTEXPR sprout::random::random_result diff --git a/sprout/random/shuffle_order.hpp b/sprout/random/shuffle_order.hpp index 0d521747..21664573 100644 --- a/sprout/random/shuffle_order.hpp +++ b/sprout/random/shuffle_order.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -79,53 +80,53 @@ namespace sprout { return base_type::static_max(); } private: - template + template static SPROUT_CONSTEXPR typename std::enable_if< (M + sizeof...(Args) == k), member_type - >::type init_member_4(sprout::index_tuple, sprout::array const& a, Random const& rnd, Args const&... args) { + >::type init_member_4(sprout::index_tuple, sprout::array const& a, EngineResult const& rnd, Args const&... args) { return member_type{ - rnd.engine(), + sprout::generators::next_generator(rnd), sprout::array{{a[Indexes]..., args...}}, - rnd.result() + sprout::generators::generated_value(rnd) }; } - template + template static SPROUT_CONSTEXPR typename std::enable_if< (M + sizeof...(Args) == k), member_type - >::type init_member_3(sprout::array const& a, Random const& rnd, Args const&... args) { + >::type init_member_3(sprout::array const& a, EngineResult const& rnd, Args const&... args) { return init_member_4(sprout::make_index_tuple::make(), a, rnd, args...); } - template + template static SPROUT_CONSTEXPR typename std::enable_if< (M + sizeof...(Args) < k), member_type - >::type init_member_3(sprout::array const& a, Random const& rnd, Args const&... args) { - return init_member_3(a, rnd(), args..., rnd.result()); + >::type init_member_3(sprout::array const& a, EngineResult const& rnd, Args const&... args) { + return init_member_3(a, sprout::generators::next_generator(rnd)(), args..., sprout::generators::generated_value(rnd)); } template static SPROUT_CONSTEXPR member_type init_member_2(Pair const& p) { return init_member_3(p.first, p.second()); } - template + template static SPROUT_CONSTEXPR typename std::enable_if< (sizeof...(Args) == k), member_type - >::type init_member_1(Random const& rnd, Args const&... args) { + >::type init_member_1(EngineResult const& rnd, Args const&... args) { return member_type{ - rnd.engine(), + sprout::generators::next_generator(rnd), sprout::array{{args...}}, - rnd.result() + sprout::generators::generated_value(rnd) }; } - template + template static SPROUT_CONSTEXPR typename std::enable_if< (sizeof...(Args) < k), member_type - >::type init_member_1(Random const& rnd, Args const&... args) { - return init_member_1(rnd(), args..., rnd.result()); + >::type init_member_1(EngineResult const& rnd, Args const&... args) { + return init_member_1(sprout::generators::next_generator(rnd)(), args..., sprout::generators::generated_value(rnd)); } static SPROUT_CONSTEXPR member_type init_member_0(base_type const& rng, std::true_type) { return init_member_2(sprout::random::generate_array(rng)); @@ -149,14 +150,14 @@ namespace sprout { ) : member_type{rng, v, y} {} - template + template SPROUT_CONSTEXPR sprout::random::random_result - generate_1(Random const& rnd, BaseUnsigned j) const { + generate_1(EngineResult const& rnd, BaseUnsigned j) const { return sprout::random::random_result( v_[j], shuffle_order_engine( - rnd.engine(), - sprout::fixed::set(v_, j, rnd.result()), + sprout::generators::next_generator(rnd), + sprout::fixed::set(v_, j, sprout::generators::generated_value(rnd)), v_[j], private_construct_t() ) diff --git a/sprout/random/uniform_01.hpp b/sprout/random/uniform_01.hpp index 8d805f4f..c6402bc4 100644 --- a/sprout/random/uniform_01.hpp +++ b/sprout/random/uniform_01.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #ifdef SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE # include #endif @@ -65,7 +66,7 @@ namespace sprout { generate_1(Engine const&, EngineResult const& rnd, result_type result) const { return result < result_type(1) ? sprout::random::random_result(result, rnd.engine(), *this) - : generate(rnd.engine(), rnd.engine()()) + : generate(sprout::generators::next_generator(rnd), sprout::generators::next_generator(rnd)()) ; } template @@ -80,7 +81,7 @@ namespace sprout { return generate_1( eng, rnd, - result_type(rnd.result() - eng.min()) * ( + result_type(sprout::generators::generated_value(rnd) - eng.min()) * ( result_type(1) / ( result_type(eng.max() - eng.min()) + result_type( sprout::numeric_limits::is_integer ? 1 : 0 @@ -100,7 +101,7 @@ namespace sprout { generate_1(Engine const&, EngineResult const& rnd, result_type result) const { return result < result_type(1) ? sprout::random::random_result(result, rnd.engine(), *this) - : generate(rnd.engine(), rnd.engine()()) + : generate(sprout::generators::next_generator(rnd), sprout::generators::next_generator(rnd)()) ; } template @@ -110,7 +111,7 @@ namespace sprout { return generate_1( eng, rnd, - result_type(rnd.result() - eng.min()) * ( + result_type(sprout::generators::generated_value(rnd) - eng.min()) * ( result_type(1) / ( result_type(eng.max() - eng.min()) + result_type( sprout::numeric_limits::is_integer ? 1 : 0 diff --git a/sprout/random/uniform_int_distribution.hpp b/sprout/random/uniform_int_distribution.hpp index fbdfd834..2921f41f 100644 --- a/sprout/random/uniform_int_distribution.hpp +++ b/sprout/random/uniform_int_distribution.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include namespace sprout { @@ -182,9 +183,9 @@ namespace sprout { ) { return sprout::random::detail::generate_uniform_int_true_3_1_1( - rnd.engine(), min_value, range, + sprout::generators::next_generator(rnd), min_value, range, bmin, brange, bucket_size, - sprout::random::detail::subtract()(rnd.result(), bmin) / bucket_size + sprout::random::detail::subtract()(sprout::generators::generated_value(rnd), bmin) / bucket_size ); } template @@ -328,14 +329,14 @@ namespace sprout { return mult * RangeType(brange) == range - mult + 1 ? sprout::random::detail::generate_uniform_int_result{ static_cast( - result + static_cast(sprout::random::detail::subtract()(rnd.result(), bmin) * mult) + result + static_cast(sprout::random::detail::subtract()(sprout::generators::generated_value(rnd), bmin) * mult) ), - rnd.engine() + sprout::generators::next_generator(rnd) } : sprout::random::detail::generate_uniform_int_true_2_1( - rnd.engine(), min_value, range, + sprout::generators::next_generator(rnd), min_value, range, bmin, brange, limit, - result + static_cast(sprout::random::detail::subtract()(rnd.result(), bmin) * mult), + result + static_cast(sprout::random::detail::subtract()(sprout::generators::generated_value(rnd), bmin) * mult), mult * (RangeType(brange) + RangeType(1)) ) ; @@ -422,10 +423,10 @@ namespace sprout { typedef typename std::make_unsigned::type base_unsigned; return sprout::random::detail::generate_uniform_int_result{ sprout::random::detail::add()( - base_unsigned(sprout::random::detail::subtract()(rnd.result(), bmin)), + base_unsigned(sprout::random::detail::subtract()(sprout::generators::generated_value(rnd), bmin)), min_value ), - rnd.engine() + sprout::generators::next_generator(rnd) }; } template @@ -556,9 +557,9 @@ namespace sprout { ) { return sprout::random::detail::generate_uniform_int_true_3_1_1( - rnd.engine(), min_value, range, + sprout::generators::next_generator(rnd), min_value, range, bmin, brange, bucket_size, - sprout::random::detail::subtract()(rnd.result(), bmin) / bucket_size + sprout::random::detail::subtract()(sprout::generators::generated_value(rnd), bmin) / bucket_size ); } template @@ -644,14 +645,14 @@ namespace sprout { return mult * RangeType(brange) == range - mult + 1 ? sprout::random::detail::generate_uniform_int_result{ static_cast( - result + static_cast(sprout::random::detail::subtract()(rnd.result(), bmin) * mult) + result + static_cast(sprout::random::detail::subtract()(sprout::generators::generated_value(rnd), bmin) * mult) ), - rnd.engine() + sprout::generators::next_generator(rnd) } : sprout::random::detail::generate_uniform_int_true_2_1( - rnd.engine(), min_value, range, + sprout::generators::next_generator(rnd), min_value, range, bmin, brange, limit, - result + static_cast(sprout::random::detail::subtract()(rnd.result(), bmin) * mult), + result + static_cast(sprout::random::detail::subtract()(sprout::generators::generated_value(rnd), bmin) * mult), mult * (RangeType(brange) + RangeType(1)) ) ; @@ -710,10 +711,10 @@ namespace sprout { typedef typename std::make_unsigned::type base_unsigned; return sprout::random::detail::generate_uniform_int_result{ sprout::random::detail::add()( - base_unsigned(sprout::random::detail::subtract()(rnd.result(), bmin)), + base_unsigned(sprout::random::detail::subtract()(sprout::generators::generated_value(rnd), bmin)), min_value ), - rnd.engine() + sprout::generators::next_generator(rnd) }; } template diff --git a/sprout/random/uniform_real_distribution.hpp b/sprout/random/uniform_real_distribution.hpp index 78e4cbd6..202d68ab 100644 --- a/sprout/random/uniform_real_distribution.hpp +++ b/sprout/random/uniform_real_distribution.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include namespace sprout { @@ -148,9 +149,10 @@ namespace sprout { ) { return sprout::random::detail::generate_uniform_real_false_2( - rnd.engine(), + sprout::generators::next_generator(rnd), min_value, max_value, - static_cast(rnd.result() - rnd.engine().min()), static_cast(rnd.engine().max() - rnd.engine().min()) + static_cast(sprout::generators::generated_value(rnd) - sprout::generators::next_generator(rnd).min()), + static_cast(sprout::generators::next_generator(rnd).max() - sprout::generators::next_generator(rnd).min()) ); } template @@ -232,10 +234,10 @@ namespace sprout { { typedef typename EngineResult::result_type base_result; return sprout::random::detail::generate_uniform_real_true_2( - rnd.engine(), + sprout::generators::next_generator(rnd), min_value, max_value, - static_cast(sprout::random::detail::subtract()(rnd.result(), rnd.engine().min())), - static_cast(sprout::random::detail::subtract()(rnd.engine().max(), rnd.engine().min())) + 1 + static_cast(sprout::random::detail::subtract()(sprout::generators::generated_value(rnd), sprout::generators::next_generator(rnd).min())), + static_cast(sprout::random::detail::subtract()(sprout::generators::next_generator(rnd).max(), sprout::generators::next_generator(rnd).min())) + 1 ); } template @@ -291,9 +293,10 @@ namespace sprout { ) { return sprout::random::detail::generate_uniform_real_false_2( - rnd.engine(), + sprout::generators::next_generator(rnd), min_value, max_value, - static_cast(rnd.result() - rnd.engine().min()), static_cast(rnd.engine().max() - rnd.engine().min()) + static_cast(sprout::generators::generated_value(rnd) - sprout::generators::next_generator(rnd).min()), + static_cast(sprout::generators::next_generator(rnd).max() - sprout::generators::next_generator(rnd).min()) ); } template @@ -340,10 +343,10 @@ namespace sprout { { typedef typename EngineResult::result_type base_result; return sprout::random::detail::generate_uniform_real_true_2( - rnd.engine(), + sprout::generators::next_generator(rnd), min_value, max_value, - static_cast(sprout::random::detail::subtract()(rnd.result(), rnd.engine().min())), - static_cast(sprout::random::detail::subtract()(rnd.engine().max(), rnd.engine().min())) + 1 + static_cast(sprout::random::detail::subtract()(sprout::generators::generated_value(rnd), sprout::generators::next_generator(rnd).min())), + static_cast(sprout::random::detail::subtract()(sprout::generators::next_generator(rnd).max(), sprout::generators::next_generator(rnd).min())) + 1 ); } #endif diff --git a/sprout/random/uniform_smallint.hpp b/sprout/random/uniform_smallint.hpp index 43f6f258..e200e57d 100644 --- a/sprout/random/uniform_smallint.hpp +++ b/sprout/random/uniform_smallint.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include namespace sprout { @@ -135,12 +136,12 @@ namespace sprout { return range >= base_range ? sprout::random::random_result( sprout::random::detail::add()(static_cast(val), min_), - rnd.engine(), + sprout::generators::next_generator(rnd), *this ) : sprout::random::random_result( sprout::random::detail::add()(static_cast(val % (static_cast(range) + 1)), min_), - rnd.engine(), + sprout::generators::next_generator(rnd), *this ) ; @@ -159,7 +160,7 @@ namespace sprout { rnd, range, base_range, - BaseUnsigned(sprout::random::detail::subtract()(rnd.result(), eng.min())) + BaseUnsigned(sprout::random::detail::subtract()(sprout::generators::generated_value(rnd), eng.min())) ); } template @@ -178,10 +179,10 @@ namespace sprout { base_unsigned(sprout::random::detail::subtract()(eng.max(), eng.min())) ); } - template + template SPROUT_CONSTEXPR sprout::random::random_result generate_false_2( Engine const&, - sprout::random::random_result > const& rnd, + Random const& rnd, RangeType range, RangeType offset ) const @@ -189,20 +190,20 @@ namespace sprout { return offset > range ? sprout::random::random_result( max_, - rnd.engine(), + sprout::generators::next_generator(rnd).engine(), *this ) : sprout::random::random_result( sprout::random::detail::add()(offset, min_), - rnd.engine(), + sprout::generators::next_generator(rnd).engine(), *this ) ; } - template + template SPROUT_CONSTEXPR sprout::random::random_result generate_false_1( Engine const& eng, - sprout::random::random_result > const& rnd, + Random const& rnd, RangeType range ) const { @@ -211,7 +212,7 @@ namespace sprout { eng, rnd, static_cast(sprout::random::detail::subtract()(max_, min_)), - static_cast(rnd.result() * (static_cast(range) + 1)) + static_cast(sprout::generators::generated_value(rnd) * (static_cast(range) + 1)) ); } template diff --git a/sprout/random/xor_combine.hpp b/sprout/random/xor_combine.hpp index 19c22b6e..a3d70394 100644 --- a/sprout/random/xor_combine.hpp +++ b/sprout/random/xor_combine.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT @@ -43,12 +44,12 @@ namespace sprout { base1_type rng1_; base2_type rng2_; private: - template - SPROUT_CONSTEXPR sprout::random::random_result generate(Random1 const& rnd1, Random2 const& rnd2) const { + template + SPROUT_CONSTEXPR sprout::random::random_result generate(EngineResult1 const& rnd1, EngineResult2 const& rnd2) const { return sprout::random::random_result( - (rnd1.result() << s1) ^ (rnd2.result() << s2), + (sprout::generators::generated_value(rnd1) << s1) ^ (sprout::generators::generated_value(rnd2) << s2), xor_combine_engine( - rnd1.engine(), rnd2.engine() + sprout::generators::next_generator(rnd1), sprout::generators::next_generator(rnd2) ) ); } diff --git a/sprout/uuid/random_generator.hpp b/sprout/uuid/random_generator.hpp index a3c5ed04..83312700 100644 --- a/sprout/uuid/random_generator.hpp +++ b/sprout/uuid/random_generator.hpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace sprout { namespace uuids { @@ -58,14 +59,14 @@ namespace sprout { sizeof...(Args) == 3, result_type >::type random_to_uuid(Random const& rnd, Args... args) const { - return random_to_uuid_1(args..., rnd.result()); + return random_to_uuid_1(args..., sprout::generators::generated_value(rnd)); } template SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) != 3, result_type >::type random_to_uuid(Random const& rnd, Args... args) const { - return random_to_uuid(rnd(), args..., rnd.result()); + return random_to_uuid(sprout::generators::next_generator(rnd)(), args..., sprout::generators::generated_value(rnd)); } public: SPROUT_CONSTEXPR basic_random_generator()