fix random generation implementation

This commit is contained in:
bolero-MURAKAMI 2014-01-16 01:04:31 +09:00
parent 406a1ff789
commit 3879666b02
18 changed files with 140 additions and 110 deletions

View file

@ -18,6 +18,7 @@
#include <sprout/utility/pair/pair.hpp> #include <sprout/utility/pair/pair.hpp>
#include <sprout/algorithm/fixed/results.hpp> #include <sprout/algorithm/fixed/results.hpp>
#include <sprout/algorithm/fixed/swap_element.hpp> #include <sprout/algorithm/fixed/swap_element.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/workaround/detail/uniform_int_distribution.hpp> #include <sprout/workaround/detail/uniform_int_distribution.hpp>
namespace sprout { namespace sprout {
@ -26,14 +27,14 @@ namespace sprout {
template<typename Random> template<typename Random>
inline SPROUT_CONSTEXPR sprout::array<std::ptrdiff_t, 2> inline SPROUT_CONSTEXPR sprout::array<std::ptrdiff_t, 2>
make_random_swap_indexes_2(Random const& rnd, std::ptrdiff_t i0) { make_random_swap_indexes_2(Random const& rnd, std::ptrdiff_t i0) {
return sprout::array<std::ptrdiff_t, 2>{{i0, rnd.result()}}; return sprout::array<std::ptrdiff_t, 2>{{i0, sprout::generators::generated_value(rnd)}};
} }
template<typename Random> template<typename Random>
inline SPROUT_CONSTEXPR sprout::array<std::ptrdiff_t, 2> inline SPROUT_CONSTEXPR sprout::array<std::ptrdiff_t, 2>
make_random_swap_indexes_1(Random const& rnd) { make_random_swap_indexes_1(Random const& rnd) {
return sprout::fixed::detail::make_random_swap_indexes_2( return sprout::fixed::detail::make_random_swap_indexes_2(
rnd(), sprout::generators::next_generator(rnd)(),
rnd.result() sprout::generators::generated_value(rnd)
); );
} }
template<typename UniformRandomNumberGenerator> template<typename UniformRandomNumberGenerator>

View file

@ -22,6 +22,7 @@
#include <sprout/utility/pair/access.hpp> #include <sprout/utility/pair/access.hpp>
#include <sprout/algorithm/fixed/results.hpp> #include <sprout/algorithm/fixed/results.hpp>
#include <sprout/algorithm/fixed/swap_element.hpp> #include <sprout/algorithm/fixed/swap_element.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/workaround/detail/uniform_int_distribution.hpp> #include <sprout/workaround/detail/uniform_int_distribution.hpp>
namespace sprout { namespace sprout {
@ -32,16 +33,16 @@ namespace sprout {
make_random_swap_result_indexes_2(Random const& rnd, std::ptrdiff_t i0) { make_random_swap_result_indexes_2(Random const& rnd, std::ptrdiff_t i0) {
typedef sprout::pair<sprout::array<std::ptrdiff_t, 2>, typename std::decay<UniformRandomNumberGenerator>::type> result_type; typedef sprout::pair<sprout::array<std::ptrdiff_t, 2>, typename std::decay<UniformRandomNumberGenerator>::type> result_type;
return result_type( return result_type(
sprout::array<std::ptrdiff_t, 2>{{i0, rnd.result()}}, sprout::array<std::ptrdiff_t, 2>{{i0, sprout::generators::generated_value(rnd)}},
rnd.engine() sprout::generators::next_generator(rnd).engine()
); );
} }
template<typename UniformRandomNumberGenerator, typename Random> template<typename UniformRandomNumberGenerator, typename Random>
inline SPROUT_CONSTEXPR sprout::pair<sprout::array<std::ptrdiff_t, 2>, typename std::decay<UniformRandomNumberGenerator>::type> inline SPROUT_CONSTEXPR sprout::pair<sprout::array<std::ptrdiff_t, 2>, typename std::decay<UniformRandomNumberGenerator>::type>
make_random_swap_result_indexes_1(Random const& rnd) { make_random_swap_result_indexes_1(Random const& rnd) {
return sprout::fixed::detail::make_random_swap_result_indexes_2<UniformRandomNumberGenerator>( return sprout::fixed::detail::make_random_swap_result_indexes_2<UniformRandomNumberGenerator>(
rnd(), sprout::generators::next_generator(rnd)(),
rnd.result() sprout::generators::generated_value(rnd)
); );
} }
template<typename UniformRandomNumberGenerator> template<typename UniformRandomNumberGenerator>

View file

@ -21,6 +21,7 @@
#include <sprout/algorithm/fixed/results.hpp> #include <sprout/algorithm/fixed/results.hpp>
#include <sprout/algorithm/fixed/swap_element.hpp> #include <sprout/algorithm/fixed/swap_element.hpp>
#include <sprout/numeric/fixed/iota.hpp> #include <sprout/numeric/fixed/iota.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/workaround/detail/uniform_int_distribution.hpp> #include <sprout/workaround/detail/uniform_int_distribution.hpp>
namespace sprout { namespace sprout {
@ -32,11 +33,11 @@ namespace sprout {
return i < n - 1 return i < n - 1
? sprout::fixed::detail::make_shuffle_indexes_1( ? sprout::fixed::detail::make_shuffle_indexes_1(
n, n,
rnd(), sprout::generators::next_generator(rnd)(),
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)),
i + 1 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<std::size_t N, typename UniformRandomNumberGenerator> template<std::size_t N, typename UniformRandomNumberGenerator>

View file

@ -24,6 +24,7 @@
#include <sprout/algorithm/fixed/results.hpp> #include <sprout/algorithm/fixed/results.hpp>
#include <sprout/algorithm/fixed/swap_element.hpp> #include <sprout/algorithm/fixed/swap_element.hpp>
#include <sprout/numeric/fixed/iota.hpp> #include <sprout/numeric/fixed/iota.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/workaround/detail/uniform_int_distribution.hpp> #include <sprout/workaround/detail/uniform_int_distribution.hpp>
namespace sprout { namespace sprout {
@ -36,13 +37,13 @@ namespace sprout {
return i < n - 1 return i < n - 1
? sprout::fixed::detail::make_shuffle_result_indexes_1<UniformRandomNumberGenerator>( ? sprout::fixed::detail::make_shuffle_result_indexes_1<UniformRandomNumberGenerator>(
n, n,
rnd(), sprout::generators::next_generator(rnd)(),
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)),
i + 1 i + 1
) )
: result_type( : result_type(
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)),
rnd.engine() sprout::generators::next_generator(rnd).engine()
) )
; ;
} }

View file

@ -15,6 +15,7 @@
#include <sprout/random/random_result.hpp> #include <sprout/random/random_result.hpp>
#include <sprout/random/linear_congruential.hpp> #include <sprout/random/linear_congruential.hpp>
#include <sprout/random/type_traits.hpp> #include <sprout/random/type_traits.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/type_traits/enabler_if.hpp> #include <sprout/type_traits/enabler_if.hpp>
namespace sprout { namespace sprout {
@ -52,12 +53,12 @@ namespace sprout {
template<typename Random1, typename Random2> template<typename Random1, typename Random2>
SPROUT_CONSTEXPR sprout::random::random_result<additive_combine_engine> generate(Random1 const& rnd1, Random2 const& rnd2) const { SPROUT_CONSTEXPR sprout::random::random_result<additive_combine_engine> generate(Random1 const& rnd1, Random2 const& rnd2) const {
return sprout::random::random_result<additive_combine_engine>( return sprout::random::random_result<additive_combine_engine>(
rnd2.result() < rnd1.result() sprout::generators::generated_value(rnd2) < sprout::generators::generated_value(rnd1)
? rnd1.result() - rnd2.result() ? sprout::generators::generated_value(rnd1) - sprout::generators::generated_value(rnd2)
: rnd1.result() - rnd2.result() + base1_type::modulus - 1 : sprout::generators::generated_value(rnd1) - sprout::generators::generated_value(rnd2) + base1_type::modulus - 1
, ,
additive_combine_engine( additive_combine_engine(
rnd1.engine(), rnd2.engine(), sprout::generators::next_generator(rnd1), sprout::generators::next_generator(rnd2),
private_construct_t() private_construct_t()
) )
); );

View file

@ -11,6 +11,7 @@
#include <iosfwd> #include <iosfwd>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/random/random_result.hpp> #include <sprout/random/random_result.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
namespace sprout { namespace sprout {
@ -82,8 +83,10 @@ namespace sprout {
) const ) const
{ {
return sprout::random::random_result<Engine, bernoulli_distribution>( return sprout::random::random_result<Engine, bernoulli_distribution>(
RealType(rnd.result() - rnd.engine().min()) <= p_ * RealType(rnd.engine().max() - rnd.engine().min()), RealType(sprout::generators::generated_value(rnd) - sprout::generators::next_generator(rnd).min())
rnd.engine(), <= p_ * RealType(sprout::generators::next_generator(rnd).max() - sprout::generators::next_generator(rnd).min())
,
sprout::generators::next_generator(rnd),
*this *this
); );
} }

View file

@ -20,6 +20,7 @@
#include <sprout/math/floor.hpp> #include <sprout/math/floor.hpp>
#include <sprout/random/random_result.hpp> #include <sprout/random/random_result.hpp>
#include <sprout/random/uniform_01.hpp> #include <sprout/random/uniform_01.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
#ifdef SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE #ifdef SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE
# include <sprout/workaround/recursive_function_template.hpp> # include <sprout/workaround/recursive_function_template.hpp>
@ -320,7 +321,7 @@ namespace sprout {
template<typename Engine, typename Random> template<typename Engine, typename Random>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution>
invert_0(IntType t, RealType p, Random const& rnd) const { 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<typename Engine> template<typename Engine>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution>
@ -330,7 +331,11 @@ namespace sprout {
template<typename Engine> template<typename Engine>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution>
invert2_0(IntType t, sprout::random::random_result<Engine, binomial_distribution> const& rnd) const { invert2_0(IntType t, sprout::random::random_result<Engine, binomial_distribution> const& rnd) const {
return sprout::random::random_result<Engine, binomial_distribution>(t - rnd.result(), rnd.engine(), rnd.distribution()); return sprout::random::random_result<Engine, binomial_distribution>(
t - sprout::generators::generated_value(rnd),
sprout::generators::next_generator(rnd).engine(),
sprout::generators::next_generator(rnd).distribution()
);
} }
template<typename Engine> template<typename Engine>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution>
@ -483,11 +488,11 @@ namespace sprout {
generate_2(Random const& rnd, RealType v) const { generate_2(Random const& rnd, RealType v) const {
return v >= btrd_.v_r return v >= btrd_.v_r
? generate_3<D + 1>( ? generate_3<D + 1>(
rnd.engine(), v, sprout::generators::next_generator(rnd).engine(), v,
rnd.result() - RealType(0.5) sprout::generators::generated_value(rnd) - RealType(0.5)
) )
: generate_3<D + 1>( : generate_3<D + 1>(
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)) ((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<int D, typename Engine, typename Random, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)> template<int D, typename Engine, typename Random, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution>
generate_0(Random const& rnd) const { generate_0(Random const& rnd) const {
return generate_1<D + 1>(rnd.engine(), rnd.result()); return generate_1<D + 1>(sprout::generators::next_generator(rnd).engine(), sprout::generators::generated_value(rnd));
} }
template<int D, typename Engine, typename Random, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)> template<int D, typename Engine, typename Random, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution>
@ -634,13 +639,13 @@ namespace sprout {
generate_2(Random const& rnd, RealType v) const { generate_2(Random const& rnd, RealType v) const {
return v >= btrd_.v_r return v >= btrd_.v_r
? generate_3( ? generate_3(
rnd.engine(), sprout::generators::next_generator(rnd).engine(),
v, v,
rnd.result() - RealType(0.5) sprout::generators::generated_value(rnd) - RealType(0.5)
) )
: generate_3( : generate_3(
rnd.engine(), sprout::generators::next_generator(rnd).engine(),
rnd.result() * btrd_.v_r, 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)) ((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<typename Engine, typename Random> template<typename Engine, typename Random>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution>
generate_0(Random const& rnd) const { 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<typename Engine> template<typename Engine>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution>
@ -676,7 +681,11 @@ namespace sprout {
template<typename Engine> template<typename Engine>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution>
generate2_0(IntType t, sprout::random::random_result<Engine, binomial_distribution> const& rnd) const { generate2_0(IntType t, sprout::random::random_result<Engine, binomial_distribution> const& rnd) const {
return sprout::random::random_result<Engine, binomial_distribution>(t - rnd.result(), rnd.engine(), rnd.distribution()); return sprout::random::random_result<Engine, binomial_distribution>(
t - sprout::generators::generated_value(rnd),
sprout::generators::next_generator(rnd).engine(),
sprout::generators::next_generator(rnd).distribution()
);
} }
template<typename Engine> template<typename Engine>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution>

View file

@ -14,13 +14,14 @@
#include <sprout/limits.hpp> #include <sprout/limits.hpp>
#include <sprout/random/random_result.hpp> #include <sprout/random/random_result.hpp>
#include <sprout/random/detail/generator_bits.hpp> #include <sprout/random/detail/generator_bits.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/detail/integer.hpp> #include <sprout/detail/integer.hpp>
#include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT #include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT
namespace sprout { namespace sprout {
namespace random { namespace random {
namespace detail { namespace detail {
template<class URNG> template<typename URNG>
class uniform_int_float { class uniform_int_float {
public: public:
typedef URNG base_type; typedef URNG base_type;
@ -38,8 +39,8 @@ namespace sprout {
) const ) const
{ {
return sprout::random::random_result<uniform_int_float>( return sprout::random::random_result<uniform_int_float>(
static_cast<result_type>(rnd.result() * (static_cast<base_result>(max()) + 1)), static_cast<result_type>(sprout::generators::generated_value(rnd) * (static_cast<base_result>(max()) + 1)),
uniform_int_float(rnd.engine()) uniform_int_float(sprout::generators::next_generator(rnd))
); );
} }
public: public:

View file

@ -15,6 +15,7 @@
#include <sprout/math/floor.hpp> #include <sprout/math/floor.hpp>
#include <sprout/random/random_result.hpp> #include <sprout/random/random_result.hpp>
#include <sprout/random/uniform_01.hpp> #include <sprout/random/uniform_01.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
namespace sprout { namespace sprout {
@ -90,8 +91,8 @@ namespace sprout {
template<typename Engine, typename Random> template<typename Engine, typename Random>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, geometric_distribution> generate_1(Random const& rnd) const { SPROUT_CONSTEXPR sprout::random::random_result<Engine, geometric_distribution> generate_1(Random const& rnd) const {
return sprout::random::random_result<Engine, geometric_distribution>( return sprout::random::random_result<Engine, geometric_distribution>(
static_cast<IntType>(sprout::math::floor(sprout::math::log(RealType(1) - rnd.result()) / log_1mp_)), static_cast<IntType>(sprout::math::floor(sprout::math::log(RealType(1) - sprout::generators::generated_value(rnd)) / log_1mp_)),
rnd.engine(), sprout::generators::next_generator(rnd).engine(),
*this *this
); );
} }

View file

@ -17,6 +17,7 @@
#include <sprout/random/detail/seed_impl.hpp> #include <sprout/random/detail/seed_impl.hpp>
#include <sprout/random/random_result.hpp> #include <sprout/random/random_result.hpp>
#include <sprout/random/type_traits.hpp> #include <sprout/random/type_traits.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/type_traits/enabler_if.hpp> #include <sprout/type_traits/enabler_if.hpp>
#include <sprout/math/greater_equal.hpp> #include <sprout/math/greater_equal.hpp>
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
@ -208,11 +209,11 @@ namespace sprout {
SPROUT_CONSTEXPR rand48(lcf_type const& lcf, private_construct_t) SPROUT_CONSTEXPR rand48(lcf_type const& lcf, private_construct_t)
: lcf_(lcf) : lcf_(lcf)
{} {}
template<typename LcfResult> template<typename EngineResult>
SPROUT_CONSTEXPR sprout::random::random_result<rand48> generate(LcfResult const& lcf_result) const { SPROUT_CONSTEXPR sprout::random::random_result<rand48> generate(EngineResult const& rnd) const {
return sprout::random::random_result<rand48>( return sprout::random::random_result<rand48>(
static_cast<result_type>(lcf_result.result()) >> 17, static_cast<result_type>(sprout::generators::generated_value(rnd)) >> 17,
rand48(lcf_result.engine(), private_construct_t()) rand48(sprout::generators::next_generator(rnd), private_construct_t())
); );
} }
public: public:

View file

@ -19,6 +19,7 @@
#include <sprout/math/sqrt.hpp> #include <sprout/math/sqrt.hpp>
#include <sprout/random/uniform_01.hpp> #include <sprout/random/uniform_01.hpp>
#include <sprout/random/random_result.hpp> #include <sprout/random/random_result.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
namespace sprout { namespace sprout {
@ -140,14 +141,14 @@ namespace sprout {
SPROUT_CONSTEXPR sprout::random::random_result<Engine, normal_distribution> SPROUT_CONSTEXPR sprout::random::random_result<Engine, normal_distribution>
generate_1_1(RealType r1, Random const& rnd) const { generate_1_1(RealType r1, Random const& rnd) const {
return generate_2( return generate_2(
rnd.engine(), r1, rnd.result(), sprout::generators::next_generator(rnd).engine(), r1, sprout::generators::generated_value(rnd),
sprout::sqrt(-result_type(2) * sprout::math::log(result_type(1) - rnd.result())), true sprout::sqrt(-result_type(2) * sprout::math::log(result_type(1) - sprout::generators::generated_value(rnd))), true
); );
} }
template<typename Engine, typename Random> template<typename Engine, typename Random>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, normal_distribution> SPROUT_CONSTEXPR sprout::random::random_result<Engine, normal_distribution>
generate_1(Random const& rnd) const { generate_1(Random const& rnd) const {
return generate_1_1<Engine>(rnd.result(), rnd()); return generate_1_1<Engine>(sprout::generators::generated_value(rnd), sprout::generators::next_generator(rnd)());
} }
template<typename Engine> template<typename Engine>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, normal_distribution> SPROUT_CONSTEXPR sprout::random::random_result<Engine, normal_distribution>

View file

@ -24,6 +24,7 @@
#include <sprout/random/detail/signed_unsigned_tools.hpp> #include <sprout/random/detail/signed_unsigned_tools.hpp>
#include <sprout/random/type_traits.hpp> #include <sprout/random/type_traits.hpp>
#include <sprout/random/generate_array.hpp> #include <sprout/random/generate_array.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/type_traits/enabler_if.hpp> #include <sprout/type_traits/enabler_if.hpp>
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
#include <sprout/workaround/recursive_function_template.hpp> #include <sprout/workaround/recursive_function_template.hpp>
@ -79,53 +80,53 @@ namespace sprout {
return base_type::static_max(); return base_type::static_max();
} }
private: private:
template<std::size_t M, typename Random, typename... Args, sprout::index_t... Indexes> template<std::size_t M, typename EngineResult, typename... Args, sprout::index_t... Indexes>
static SPROUT_CONSTEXPR typename std::enable_if< static SPROUT_CONSTEXPR typename std::enable_if<
(M + sizeof...(Args) == k), (M + sizeof...(Args) == k),
member_type member_type
>::type init_member_4(sprout::index_tuple<Indexes...>, sprout::array<result_type, M> const& a, Random const& rnd, Args const&... args) { >::type init_member_4(sprout::index_tuple<Indexes...>, sprout::array<result_type, M> const& a, EngineResult const& rnd, Args const&... args) {
return member_type{ return member_type{
rnd.engine(), sprout::generators::next_generator(rnd),
sprout::array<result_type, k>{{a[Indexes]..., args...}}, sprout::array<result_type, k>{{a[Indexes]..., args...}},
rnd.result() sprout::generators::generated_value(rnd)
}; };
} }
template<std::size_t M, typename Random, typename... Args> template<std::size_t M, typename EngineResult, typename... Args>
static SPROUT_CONSTEXPR typename std::enable_if< static SPROUT_CONSTEXPR typename std::enable_if<
(M + sizeof...(Args) == k), (M + sizeof...(Args) == k),
member_type member_type
>::type init_member_3(sprout::array<result_type, M> const& a, Random const& rnd, Args const&... args) { >::type init_member_3(sprout::array<result_type, M> const& a, EngineResult const& rnd, Args const&... args) {
return init_member_4(sprout::make_index_tuple<M>::make(), a, rnd, args...); return init_member_4(sprout::make_index_tuple<M>::make(), a, rnd, args...);
} }
template<std::size_t M, typename Random, typename... Args> template<std::size_t M, typename EngineResult, typename... Args>
static SPROUT_CONSTEXPR typename std::enable_if< static SPROUT_CONSTEXPR typename std::enable_if<
(M + sizeof...(Args) < k), (M + sizeof...(Args) < k),
member_type member_type
>::type init_member_3(sprout::array<result_type, M> const& a, Random const& rnd, Args const&... args) { >::type init_member_3(sprout::array<result_type, M> const& a, EngineResult const& rnd, Args const&... args) {
return init_member_3(a, rnd(), args..., rnd.result()); return init_member_3(a, sprout::generators::next_generator(rnd)(), args..., sprout::generators::generated_value(rnd));
} }
template<typename Pair> template<typename Pair>
static SPROUT_CONSTEXPR member_type init_member_2(Pair const& p) { static SPROUT_CONSTEXPR member_type init_member_2(Pair const& p) {
return init_member_3(p.first, p.second()); return init_member_3(p.first, p.second());
} }
template<typename Random, typename... Args> template<typename EngineResult, typename... Args>
static SPROUT_CONSTEXPR typename std::enable_if< static SPROUT_CONSTEXPR typename std::enable_if<
(sizeof...(Args) == k), (sizeof...(Args) == k),
member_type 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{ return member_type{
rnd.engine(), sprout::generators::next_generator(rnd),
sprout::array<result_type, k>{{args...}}, sprout::array<result_type, k>{{args...}},
rnd.result() sprout::generators::generated_value(rnd)
}; };
} }
template<typename Random, typename... Args> template<typename EngineResult, typename... Args>
static SPROUT_CONSTEXPR typename std::enable_if< static SPROUT_CONSTEXPR typename std::enable_if<
(sizeof...(Args) < k), (sizeof...(Args) < k),
member_type member_type
>::type init_member_1(Random const& rnd, Args const&... args) { >::type init_member_1(EngineResult const& rnd, Args const&... args) {
return init_member_1(rnd(), args..., rnd.result()); 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) { static SPROUT_CONSTEXPR member_type init_member_0(base_type const& rng, std::true_type) {
return init_member_2(sprout::random::generate_array<k / 2>(rng)); return init_member_2(sprout::random::generate_array<k / 2>(rng));
@ -149,14 +150,14 @@ namespace sprout {
) )
: member_type{rng, v, y} : member_type{rng, v, y}
{} {}
template<typename Random, typename BaseUnsigned> template<typename EngineResult, typename BaseUnsigned>
SPROUT_CONSTEXPR sprout::random::random_result<shuffle_order_engine> SPROUT_CONSTEXPR sprout::random::random_result<shuffle_order_engine>
generate_1(Random const& rnd, BaseUnsigned j) const { generate_1(EngineResult const& rnd, BaseUnsigned j) const {
return sprout::random::random_result<shuffle_order_engine>( return sprout::random::random_result<shuffle_order_engine>(
v_[j], v_[j],
shuffle_order_engine( shuffle_order_engine(
rnd.engine(), sprout::generators::next_generator(rnd),
sprout::fixed::set(v_, j, rnd.result()), sprout::fixed::set(v_, j, sprout::generators::generated_value(rnd)),
v_[j], v_[j],
private_construct_t() private_construct_t()
) )

View file

@ -13,6 +13,7 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/limits.hpp> #include <sprout/limits.hpp>
#include <sprout/random/random_result.hpp> #include <sprout/random/random_result.hpp>
#include <sprout/generator/functions.hpp>
#ifdef SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE #ifdef SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE
# include <sprout/workaround/recursive_function_template.hpp> # include <sprout/workaround/recursive_function_template.hpp>
#endif #endif
@ -65,7 +66,7 @@ namespace sprout {
generate_1(Engine const&, EngineResult const& rnd, result_type result) const { generate_1(Engine const&, EngineResult const& rnd, result_type result) const {
return result < result_type(1) return result < result_type(1)
? sprout::random::random_result<Engine, uniform_01>(result, rnd.engine(), *this) ? sprout::random::random_result<Engine, uniform_01>(result, rnd.engine(), *this)
: generate<D + 1>(rnd.engine(), rnd.engine()()) : generate<D + 1>(sprout::generators::next_generator(rnd), sprout::generators::next_generator(rnd)())
; ;
} }
template<int D, typename Engine, typename EngineResult, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)> template<int D, typename Engine, typename EngineResult, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
@ -80,7 +81,7 @@ namespace sprout {
return generate_1<D + 1>( return generate_1<D + 1>(
eng, eng,
rnd, rnd,
result_type(rnd.result() - eng.min()) * ( result_type(sprout::generators::generated_value(rnd) - eng.min()) * (
result_type(1) / ( result_type(1) / (
result_type(eng.max() - eng.min()) + result_type( result_type(eng.max() - eng.min()) + result_type(
sprout::numeric_limits<base_result>::is_integer ? 1 : 0 sprout::numeric_limits<base_result>::is_integer ? 1 : 0
@ -100,7 +101,7 @@ namespace sprout {
generate_1(Engine const&, EngineResult const& rnd, result_type result) const { generate_1(Engine const&, EngineResult const& rnd, result_type result) const {
return result < result_type(1) return result < result_type(1)
? sprout::random::random_result<Engine, uniform_01>(result, rnd.engine(), *this) ? sprout::random::random_result<Engine, uniform_01>(result, rnd.engine(), *this)
: generate(rnd.engine(), rnd.engine()()) : generate(sprout::generators::next_generator(rnd), sprout::generators::next_generator(rnd)())
; ;
} }
template<typename Engine, typename EngineResult> template<typename Engine, typename EngineResult>
@ -110,7 +111,7 @@ namespace sprout {
return generate_1( return generate_1(
eng, eng,
rnd, rnd,
result_type(rnd.result() - eng.min()) * ( result_type(sprout::generators::generated_value(rnd) - eng.min()) * (
result_type(1) / ( result_type(1) / (
result_type(eng.max() - eng.min()) + result_type( result_type(eng.max() - eng.min()) + result_type(
sprout::numeric_limits<base_result>::is_integer ? 1 : 0 sprout::numeric_limits<base_result>::is_integer ? 1 : 0

View file

@ -16,6 +16,7 @@
#include <sprout/random/detail/signed_unsigned_tools.hpp> #include <sprout/random/detail/signed_unsigned_tools.hpp>
#include <sprout/random/detail/uniform_int_float.hpp> #include <sprout/random/detail/uniform_int_float.hpp>
#include <sprout/random/random_result.hpp> #include <sprout/random/random_result.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
namespace sprout { namespace sprout {
@ -182,9 +183,9 @@ namespace sprout {
) )
{ {
return sprout::random::detail::generate_uniform_int_true_3_1_1<D + 1>( return sprout::random::detail::generate_uniform_int_true_3_1_1<D + 1>(
rnd.engine(), min_value, range, sprout::generators::next_generator(rnd), min_value, range,
bmin, brange, bucket_size, bmin, brange, bucket_size,
sprout::random::detail::subtract<BaseResult>()(rnd.result(), bmin) / bucket_size sprout::random::detail::subtract<BaseResult>()(sprout::generators::generated_value(rnd), bmin) / bucket_size
); );
} }
template<int D, typename EngineResult, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK_DECL(D)> template<int D, typename EngineResult, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK_DECL(D)>
@ -328,14 +329,14 @@ namespace sprout {
return mult * RangeType(brange) == range - mult + 1 return mult * RangeType(brange) == range - mult + 1
? sprout::random::detail::generate_uniform_int_result<T, typename EngineResult::engine_type>{ ? sprout::random::detail::generate_uniform_int_result<T, typename EngineResult::engine_type>{
static_cast<T>( static_cast<T>(
result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(rnd.result(), bmin) * mult) result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(sprout::generators::generated_value(rnd), bmin) * mult)
), ),
rnd.engine() sprout::generators::next_generator(rnd)
} }
: sprout::random::detail::generate_uniform_int_true_2_1<D + 1>( : sprout::random::detail::generate_uniform_int_true_2_1<D + 1>(
rnd.engine(), min_value, range, sprout::generators::next_generator(rnd), min_value, range,
bmin, brange, limit, bmin, brange, limit,
result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(rnd.result(), bmin) * mult), result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(sprout::generators::generated_value(rnd), bmin) * mult),
mult * (RangeType(brange) + RangeType(1)) mult * (RangeType(brange) + RangeType(1))
) )
; ;
@ -422,10 +423,10 @@ namespace sprout {
typedef typename std::make_unsigned<BaseResult>::type base_unsigned; typedef typename std::make_unsigned<BaseResult>::type base_unsigned;
return sprout::random::detail::generate_uniform_int_result<T, typename EngineResult::engine_type>{ return sprout::random::detail::generate_uniform_int_result<T, typename EngineResult::engine_type>{
sprout::random::detail::add<base_unsigned, result_type>()( sprout::random::detail::add<base_unsigned, result_type>()(
base_unsigned(sprout::random::detail::subtract<BaseResult>()(rnd.result(), bmin)), base_unsigned(sprout::random::detail::subtract<BaseResult>()(sprout::generators::generated_value(rnd), bmin)),
min_value min_value
), ),
rnd.engine() sprout::generators::next_generator(rnd)
}; };
} }
template<int D, typename EngineResult, typename T, typename BaseResult, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)> template<int D, typename EngineResult, typename T, typename BaseResult, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
@ -556,9 +557,9 @@ namespace sprout {
) )
{ {
return sprout::random::detail::generate_uniform_int_true_3_1_1( 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, bmin, brange, bucket_size,
sprout::random::detail::subtract<BaseResult>()(rnd.result(), bmin) / bucket_size sprout::random::detail::subtract<BaseResult>()(sprout::generators::generated_value(rnd), bmin) / bucket_size
); );
} }
template<typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned> template<typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned>
@ -644,14 +645,14 @@ namespace sprout {
return mult * RangeType(brange) == range - mult + 1 return mult * RangeType(brange) == range - mult + 1
? sprout::random::detail::generate_uniform_int_result<T, typename EngineResult::engine_type>{ ? sprout::random::detail::generate_uniform_int_result<T, typename EngineResult::engine_type>{
static_cast<T>( static_cast<T>(
result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(rnd.result(), bmin) * mult) result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(sprout::generators::generated_value(rnd), bmin) * mult)
), ),
rnd.engine() sprout::generators::next_generator(rnd)
} }
: sprout::random::detail::generate_uniform_int_true_2_1( : 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, bmin, brange, limit,
result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(rnd.result(), bmin) * mult), result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(sprout::generators::generated_value(rnd), bmin) * mult),
mult * (RangeType(brange) + RangeType(1)) mult * (RangeType(brange) + RangeType(1))
) )
; ;
@ -710,10 +711,10 @@ namespace sprout {
typedef typename std::make_unsigned<BaseResult>::type base_unsigned; typedef typename std::make_unsigned<BaseResult>::type base_unsigned;
return sprout::random::detail::generate_uniform_int_result<T, typename EngineResult::engine_type>{ return sprout::random::detail::generate_uniform_int_result<T, typename EngineResult::engine_type>{
sprout::random::detail::add<base_unsigned, result_type>()( sprout::random::detail::add<base_unsigned, result_type>()(
base_unsigned(sprout::random::detail::subtract<BaseResult>()(rnd.result(), bmin)), base_unsigned(sprout::random::detail::subtract<BaseResult>()(sprout::generators::generated_value(rnd), bmin)),
min_value min_value
), ),
rnd.engine() sprout::generators::next_generator(rnd)
}; };
} }
template<typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned> template<typename Engine, typename T, typename RangeType, typename BaseResult, typename BaseUnsigned>

View file

@ -14,6 +14,7 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/random/detail/signed_unsigned_tools.hpp> #include <sprout/random/detail/signed_unsigned_tools.hpp>
#include <sprout/random/random_result.hpp> #include <sprout/random/random_result.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
namespace sprout { namespace sprout {
@ -148,9 +149,10 @@ namespace sprout {
) )
{ {
return sprout::random::detail::generate_uniform_real_false_2<D + 1>( return sprout::random::detail::generate_uniform_real_false_2<D + 1>(
rnd.engine(), sprout::generators::next_generator(rnd),
min_value, max_value, min_value, max_value,
static_cast<T>(rnd.result() - rnd.engine().min()), static_cast<T>(rnd.engine().max() - rnd.engine().min()) static_cast<T>(sprout::generators::generated_value(rnd) - sprout::generators::next_generator(rnd).min()),
static_cast<T>(sprout::generators::next_generator(rnd).max() - sprout::generators::next_generator(rnd).min())
); );
} }
template<int D, typename EngineResult, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK_DECL(D)> template<int D, typename EngineResult, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK_DECL(D)>
@ -232,10 +234,10 @@ namespace sprout {
{ {
typedef typename EngineResult::result_type base_result; typedef typename EngineResult::result_type base_result;
return sprout::random::detail::generate_uniform_real_true_2<D + 1>( return sprout::random::detail::generate_uniform_real_true_2<D + 1>(
rnd.engine(), sprout::generators::next_generator(rnd),
min_value, max_value, min_value, max_value,
static_cast<T>(sprout::random::detail::subtract<base_result>()(rnd.result(), rnd.engine().min())), static_cast<T>(sprout::random::detail::subtract<base_result>()(sprout::generators::generated_value(rnd), sprout::generators::next_generator(rnd).min())),
static_cast<T>(sprout::random::detail::subtract<base_result>()(rnd.engine().max(), rnd.engine().min())) + 1 static_cast<T>(sprout::random::detail::subtract<base_result>()(sprout::generators::next_generator(rnd).max(), sprout::generators::next_generator(rnd).min())) + 1
); );
} }
template<int D, typename EngineResult, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK_DECL(D)> template<int D, typename EngineResult, typename T, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK_DECL(D)>
@ -291,9 +293,10 @@ namespace sprout {
) )
{ {
return sprout::random::detail::generate_uniform_real_false_2( return sprout::random::detail::generate_uniform_real_false_2(
rnd.engine(), sprout::generators::next_generator(rnd),
min_value, max_value, min_value, max_value,
static_cast<T>(rnd.result() - rnd.engine().min()), static_cast<T>(rnd.engine().max() - rnd.engine().min()) static_cast<T>(sprout::generators::generated_value(rnd) - sprout::generators::next_generator(rnd).min()),
static_cast<T>(sprout::generators::next_generator(rnd).max() - sprout::generators::next_generator(rnd).min())
); );
} }
template<typename EngineResult, typename T> template<typename EngineResult, typename T>
@ -340,10 +343,10 @@ namespace sprout {
{ {
typedef typename EngineResult::result_type base_result; typedef typename EngineResult::result_type base_result;
return sprout::random::detail::generate_uniform_real_true_2( return sprout::random::detail::generate_uniform_real_true_2(
rnd.engine(), sprout::generators::next_generator(rnd),
min_value, max_value, min_value, max_value,
static_cast<T>(sprout::random::detail::subtract<base_result>()(rnd.result(), rnd.engine().min())), static_cast<T>(sprout::random::detail::subtract<base_result>()(sprout::generators::generated_value(rnd), sprout::generators::next_generator(rnd).min())),
static_cast<T>(sprout::random::detail::subtract<base_result>()(rnd.engine().max(), rnd.engine().min())) + 1 static_cast<T>(sprout::random::detail::subtract<base_result>()(sprout::generators::next_generator(rnd).max(), sprout::generators::next_generator(rnd).min())) + 1
); );
} }
#endif #endif

View file

@ -16,6 +16,7 @@
#include <sprout/random/detail/signed_unsigned_tools.hpp> #include <sprout/random/detail/signed_unsigned_tools.hpp>
#include <sprout/random/random_result.hpp> #include <sprout/random/random_result.hpp>
#include <sprout/random/uniform_01.hpp> #include <sprout/random/uniform_01.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
namespace sprout { namespace sprout {
@ -135,12 +136,12 @@ namespace sprout {
return range >= base_range return range >= base_range
? sprout::random::random_result<Engine, uniform_smallint>( ? sprout::random::random_result<Engine, uniform_smallint>(
sprout::random::detail::add<RangeType, result_type>()(static_cast<RangeType>(val), min_), sprout::random::detail::add<RangeType, result_type>()(static_cast<RangeType>(val), min_),
rnd.engine(), sprout::generators::next_generator(rnd),
*this *this
) )
: sprout::random::random_result<Engine, uniform_smallint>( : sprout::random::random_result<Engine, uniform_smallint>(
sprout::random::detail::add<RangeType, result_type>()(static_cast<RangeType>(val % (static_cast<BaseUnsigned>(range) + 1)), min_), sprout::random::detail::add<RangeType, result_type>()(static_cast<RangeType>(val % (static_cast<BaseUnsigned>(range) + 1)), min_),
rnd.engine(), sprout::generators::next_generator(rnd),
*this *this
) )
; ;
@ -159,7 +160,7 @@ namespace sprout {
rnd, rnd,
range, range,
base_range, base_range,
BaseUnsigned(sprout::random::detail::subtract<base_result>()(rnd.result(), eng.min())) BaseUnsigned(sprout::random::detail::subtract<base_result>()(sprout::generators::generated_value(rnd), eng.min()))
); );
} }
template<typename Engine> template<typename Engine>
@ -178,10 +179,10 @@ namespace sprout {
base_unsigned(sprout::random::detail::subtract<result_type>()(eng.max(), eng.min())) base_unsigned(sprout::random::detail::subtract<result_type>()(eng.max(), eng.min()))
); );
} }
template<typename Engine, typename RangeType> template<typename Engine, typename Random, typename RangeType>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, uniform_smallint> generate_false_2( SPROUT_CONSTEXPR sprout::random::random_result<Engine, uniform_smallint> generate_false_2(
Engine const&, Engine const&,
sprout::random::random_result<Engine, sprout::random::uniform_01<typename Engine::result_type> > const& rnd, Random const& rnd,
RangeType range, RangeType range,
RangeType offset RangeType offset
) const ) const
@ -189,20 +190,20 @@ namespace sprout {
return offset > range return offset > range
? sprout::random::random_result<Engine, uniform_smallint>( ? sprout::random::random_result<Engine, uniform_smallint>(
max_, max_,
rnd.engine(), sprout::generators::next_generator(rnd).engine(),
*this *this
) )
: sprout::random::random_result<Engine, uniform_smallint>( : sprout::random::random_result<Engine, uniform_smallint>(
sprout::random::detail::add<RangeType, result_type>()(offset, min_), sprout::random::detail::add<RangeType, result_type>()(offset, min_),
rnd.engine(), sprout::generators::next_generator(rnd).engine(),
*this *this
) )
; ;
} }
template<typename Engine, typename RangeType> template<typename Engine, typename Random, typename RangeType>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, uniform_smallint> generate_false_1( SPROUT_CONSTEXPR sprout::random::random_result<Engine, uniform_smallint> generate_false_1(
Engine const& eng, Engine const& eng,
sprout::random::random_result<Engine, sprout::random::uniform_01<typename Engine::result_type> > const& rnd, Random const& rnd,
RangeType range RangeType range
) const ) const
{ {
@ -211,7 +212,7 @@ namespace sprout {
eng, eng,
rnd, rnd,
static_cast<RangeType>(sprout::random::detail::subtract<result_type>()(max_, min_)), static_cast<RangeType>(sprout::random::detail::subtract<result_type>()(max_, min_)),
static_cast<RangeType>(rnd.result() * (static_cast<base_result>(range) + 1)) static_cast<RangeType>(sprout::generators::generated_value(rnd) * (static_cast<base_result>(range) + 1))
); );
} }
template<class Engine> template<class Engine>

View file

@ -13,6 +13,7 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/random/random_result.hpp> #include <sprout/random/random_result.hpp>
#include <sprout/random/type_traits.hpp> #include <sprout/random/type_traits.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/type_traits/enabler_if.hpp> #include <sprout/type_traits/enabler_if.hpp>
#include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT #include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT
@ -43,12 +44,12 @@ namespace sprout {
base1_type rng1_; base1_type rng1_;
base2_type rng2_; base2_type rng2_;
private: private:
template<typename Random1, typename Random2> template<typename EngineResult1, typename EngineResult2>
SPROUT_CONSTEXPR sprout::random::random_result<xor_combine_engine> generate(Random1 const& rnd1, Random2 const& rnd2) const { SPROUT_CONSTEXPR sprout::random::random_result<xor_combine_engine> generate(EngineResult1 const& rnd1, EngineResult2 const& rnd2) const {
return sprout::random::random_result<xor_combine_engine>( return sprout::random::random_result<xor_combine_engine>(
(rnd1.result() << s1) ^ (rnd2.result() << s2), (sprout::generators::generated_value(rnd1) << s1) ^ (sprout::generators::generated_value(rnd2) << s2),
xor_combine_engine( xor_combine_engine(
rnd1.engine(), rnd2.engine() sprout::generators::next_generator(rnd1), sprout::generators::next_generator(rnd2)
) )
); );
} }

View file

@ -16,6 +16,7 @@
#include <sprout/random/default_random_engine.hpp> #include <sprout/random/default_random_engine.hpp>
#include <sprout/random/uniform_int_distribution.hpp> #include <sprout/random/uniform_int_distribution.hpp>
#include <sprout/random/variate_generator.hpp> #include <sprout/random/variate_generator.hpp>
#include <sprout/generator/functions.hpp>
namespace sprout { namespace sprout {
namespace uuids { namespace uuids {
@ -58,14 +59,14 @@ namespace sprout {
sizeof...(Args) == 3, sizeof...(Args) == 3,
result_type result_type
>::type random_to_uuid(Random const& rnd, Args... args) const { >::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<typename Random, typename... Args> template<typename Random, typename... Args>
SPROUT_CONSTEXPR typename std::enable_if< SPROUT_CONSTEXPR typename std::enable_if<
sizeof...(Args) != 3, sizeof...(Args) != 3,
result_type result_type
>::type random_to_uuid(Random const& rnd, Args... args) const { >::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: public:
SPROUT_CONSTEXPR basic_random_generator() SPROUT_CONSTEXPR basic_random_generator()