add random::result, random::next

This commit is contained in:
bolero-MURAKAMI 2014-01-16 18:59:25 +09:00
parent 3879666b02
commit 769e18178a
23 changed files with 191 additions and 136 deletions

View file

@ -18,7 +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/random/result.hpp>
#include <sprout/workaround/detail/uniform_int_distribution.hpp> #include <sprout/workaround/detail/uniform_int_distribution.hpp>
namespace sprout { namespace sprout {
@ -27,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, sprout::generators::generated_value(rnd)}}; return sprout::array<std::ptrdiff_t, 2>{{i0, sprout::random::result(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(
sprout::generators::next_generator(rnd)(), sprout::random::next(rnd)(),
sprout::generators::generated_value(rnd) sprout::random::result(rnd)
); );
} }
template<typename UniformRandomNumberGenerator> template<typename UniformRandomNumberGenerator>

View file

@ -22,7 +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/random/result.hpp>
#include <sprout/workaround/detail/uniform_int_distribution.hpp> #include <sprout/workaround/detail/uniform_int_distribution.hpp>
namespace sprout { namespace sprout {
@ -33,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, sprout::generators::generated_value(rnd)}}, sprout::array<std::ptrdiff_t, 2>{{i0, sprout::random::result(rnd)}},
sprout::generators::next_generator(rnd).engine() sprout::random::next(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>(
sprout::generators::next_generator(rnd)(), sprout::random::next(rnd)(),
sprout::generators::generated_value(rnd) sprout::random::result(rnd)
); );
} }
template<typename UniformRandomNumberGenerator> template<typename UniformRandomNumberGenerator>

View file

@ -21,7 +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/random/result.hpp>
#include <sprout/workaround/detail/uniform_int_distribution.hpp> #include <sprout/workaround/detail/uniform_int_distribution.hpp>
namespace sprout { namespace sprout {
@ -33,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,
sprout::generators::next_generator(rnd)(), sprout::random::next(rnd)(),
sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + sprout::generators::generated_value(rnd)), sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + sprout::random::result(rnd)),
i + 1 i + 1
) )
: sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + sprout::generators::generated_value(rnd)) : sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + sprout::random::result(rnd))
; ;
} }
template<std::size_t N, typename UniformRandomNumberGenerator> template<std::size_t N, typename UniformRandomNumberGenerator>

View file

@ -24,7 +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/random/result.hpp>
#include <sprout/workaround/detail/uniform_int_distribution.hpp> #include <sprout/workaround/detail/uniform_int_distribution.hpp>
namespace sprout { namespace sprout {
@ -37,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,
sprout::generators::next_generator(rnd)(), sprout::random::next(rnd)(),
sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + sprout::generators::generated_value(rnd)), sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + sprout::random::result(rnd)),
i + 1 i + 1
) )
: result_type( : result_type(
sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + sprout::generators::generated_value(rnd)), sprout::fixed::swap_element(arr, arr.begin() + i, arr.begin() + sprout::random::result(rnd)),
sprout::generators::next_generator(rnd).engine() sprout::random::next(rnd).engine()
) )
; ;
} }

View file

@ -15,7 +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/random/result.hpp>
#include <sprout/type_traits/enabler_if.hpp> #include <sprout/type_traits/enabler_if.hpp>
namespace sprout { namespace sprout {
@ -53,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>(
sprout::generators::generated_value(rnd2) < sprout::generators::generated_value(rnd1) sprout::random::result(rnd2) < sprout::random::result(rnd1)
? sprout::generators::generated_value(rnd1) - sprout::generators::generated_value(rnd2) ? sprout::random::result(rnd1) - sprout::random::result(rnd2)
: sprout::generators::generated_value(rnd1) - sprout::generators::generated_value(rnd2) + base1_type::modulus - 1 : sprout::random::result(rnd1) - sprout::random::result(rnd2) + base1_type::modulus - 1
, ,
additive_combine_engine( additive_combine_engine(
sprout::generators::next_generator(rnd1), sprout::generators::next_generator(rnd2), sprout::random::next(rnd1), sprout::random::next(rnd2),
private_construct_t() private_construct_t()
) )
); );

View file

@ -11,7 +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/random/result.hpp>
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
namespace sprout { namespace sprout {
@ -83,10 +83,10 @@ namespace sprout {
) const ) const
{ {
return sprout::random::random_result<Engine, bernoulli_distribution>( return sprout::random::random_result<Engine, bernoulli_distribution>(
RealType(sprout::generators::generated_value(rnd) - sprout::generators::next_generator(rnd).min()) RealType(sprout::random::result(rnd) - sprout::random::next(rnd).min())
<= p_ * RealType(sprout::generators::next_generator(rnd).max() - sprout::generators::next_generator(rnd).min()) <= p_ * RealType(sprout::random::next(rnd).max() - sprout::random::next(rnd).min())
, ,
sprout::generators::next_generator(rnd), sprout::random::next(rnd),
*this *this
); );
} }

View file

@ -20,7 +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/random/result.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>
@ -321,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, sprout::generators::next_generator(rnd).engine(), sprout::generators::generated_value(rnd)); return invert_1(t, p, sprout::random::next(rnd).engine(), sprout::random::result(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>
@ -332,9 +332,9 @@ namespace sprout {
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>( return sprout::random::random_result<Engine, binomial_distribution>(
t - sprout::generators::generated_value(rnd), t - sprout::random::result(rnd),
sprout::generators::next_generator(rnd).engine(), sprout::random::next(rnd).engine(),
sprout::generators::next_generator(rnd).distribution() sprout::random::next(rnd).distribution()
); );
} }
template<typename Engine> template<typename Engine>
@ -488,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>(
sprout::generators::next_generator(rnd).engine(), v, sprout::random::next(rnd).engine(), v,
sprout::generators::generated_value(rnd) - RealType(0.5) sprout::random::result(rnd) - RealType(0.5)
) )
: generate_3<D + 1>( : generate_3<D + 1>(
sprout::generators::next_generator(rnd).engine(), sprout::generators::generated_value(rnd) * btrd_.v_r, sprout::random::next(rnd).engine(), sprout::random::result(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))
) )
; ;
@ -531,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>(sprout::generators::next_generator(rnd).engine(), sprout::generators::generated_value(rnd)); return generate_1<D + 1>(sprout::random::next(rnd).engine(), sprout::random::result(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>
@ -639,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(
sprout::generators::next_generator(rnd).engine(), sprout::random::next(rnd).engine(),
v, v,
sprout::generators::generated_value(rnd) - RealType(0.5) sprout::random::result(rnd) - RealType(0.5)
) )
: generate_3( : generate_3(
sprout::generators::next_generator(rnd).engine(), sprout::random::next(rnd).engine(),
sprout::generators::generated_value(rnd) * btrd_.v_r, sprout::random::result(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))
) )
; ;
@ -670,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(sprout::generators::next_generator(rnd).engine(), sprout::generators::generated_value(rnd)); return generate_1(sprout::random::next(rnd).engine(), sprout::random::result(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>
@ -682,9 +682,9 @@ namespace sprout {
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>( return sprout::random::random_result<Engine, binomial_distribution>(
t - sprout::generators::generated_value(rnd), t - sprout::random::result(rnd),
sprout::generators::next_generator(rnd).engine(), sprout::random::next(rnd).engine(),
sprout::generators::next_generator(rnd).distribution() sprout::random::next(rnd).distribution()
); );
} }
template<typename Engine> template<typename Engine>

View file

@ -14,7 +14,7 @@
#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/random/result.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
@ -39,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>(sprout::generators::generated_value(rnd) * (static_cast<base_result>(max()) + 1)), static_cast<result_type>(sprout::random::result(rnd) * (static_cast<base_result>(max()) + 1)),
uniform_int_float(sprout::generators::next_generator(rnd)) uniform_int_float(sprout::random::next(rnd))
); );
} }
public: public:

View file

@ -12,7 +12,7 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/array/array.hpp> #include <sprout/array/array.hpp>
#include <sprout/utility/pair/pair.hpp> #include <sprout/utility/pair/pair.hpp>
#include <sprout/generator/functions.hpp> #include <sprout/random/result.hpp>
#include <sprout/generator/results.hpp> #include <sprout/generator/results.hpp>
namespace sprout { namespace sprout {
@ -44,8 +44,8 @@ namespace sprout {
typename sprout::generators::results::next_generator<RandomNumberGenerator const>::type typename sprout::generators::results::next_generator<RandomNumberGenerator const>::type
> const pair_type; > const pair_type;
return pair_type{ return pair_type{
sprout::array<typename RandomNumberGenerator::result_type, N>{{args..., sprout::generators::generated_value(rnd)}}, sprout::array<typename RandomNumberGenerator::result_type, N>{{args..., sprout::random::result(rnd)}},
sprout::generators::next_generator(rnd) sprout::random::next(rnd)
}; };
} }
template<std::size_t N, typename RandomNumberGenerator, typename Random, typename... Args> template<std::size_t N, typename RandomNumberGenerator, typename Random, typename... Args>
@ -57,8 +57,8 @@ namespace sprout {
> const > const
>::type generate_array_impl(Random const& rnd, Args const&... args) { >::type generate_array_impl(Random const& rnd, Args const&... args) {
return sprout::random::detail::generate_array_impl<N, RandomNumberGenerator>( return sprout::random::detail::generate_array_impl<N, RandomNumberGenerator>(
sprout::generators::next_generator(rnd)(), sprout::random::next(rnd)(),
args..., sprout::generators::generated_value(rnd) args..., sprout::random::result(rnd)
); );
} }
} // namespace detail } // namespace detail

View file

@ -18,7 +18,7 @@
#include <sprout/random/detail/const_mod.hpp> #include <sprout/random/detail/const_mod.hpp>
#include <sprout/random/detail/signed_unsigned_tools.hpp> #include <sprout/random/detail/signed_unsigned_tools.hpp>
#include <sprout/random/detail/generator_bits.hpp> #include <sprout/random/detail/generator_bits.hpp>
#include <sprout/generator/functions.hpp> #include <sprout/random/result.hpp>
#include <sprout/utility/pair/pair.hpp> #include <sprout/utility/pair/pair.hpp>
#include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT #include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT
@ -92,8 +92,8 @@ namespace sprout {
r, limit, r, limit,
s + RealType( s + RealType(
sprout::random::detail::subtract<base_result>()( sprout::random::detail::subtract<base_result>()(
sprout::generators::generated_value(rnd), sprout::random::result(rnd),
sprout::generators::next_generator(rnd).min() sprout::random::next(rnd).min()
) )
) * mult, ) * mult,
mult * r, mult * r,
@ -102,11 +102,11 @@ namespace sprout {
: pair_type( : pair_type(
(s + RealType( (s + RealType(
sprout::random::detail::subtract<base_result>()( sprout::random::detail::subtract<base_result>()(
sprout::generators::generated_value(rnd), sprout::random::result(rnd),
sprout::generators::next_generator(rnd).min() sprout::random::next(rnd).min()
) )
) * mult) / (mult * r), ) * mult) / (mult * r),
sprout::generators::next_generator(rnd) sprout::random::next(rnd)
) )
; ;
} }
@ -119,8 +119,8 @@ namespace sprout {
r, limit, r, limit,
RealType( RealType(
sprout::random::detail::subtract<base_result>()( sprout::random::detail::subtract<base_result>()(
sprout::generators::generated_value(rnd), sprout::random::result(rnd),
sprout::generators::next_generator(rnd).min() sprout::random::next(rnd).min()
) )
), ),
r, r,
@ -129,11 +129,11 @@ namespace sprout {
: pair_type( : pair_type(
RealType( RealType(
sprout::random::detail::subtract<base_result>()( sprout::random::detail::subtract<base_result>()(
sprout::generators::generated_value(rnd), sprout::random::result(rnd),
sprout::generators::next_generator(rnd).min() sprout::random::next(rnd).min()
) )
) / r, ) / r,
sprout::generators::next_generator(rnd) sprout::random::next(rnd)
) )
; ;
} }
@ -157,16 +157,16 @@ namespace sprout {
return mult * r < limit ? sprout::random::detail::generate_canonical_impl_0_1<RealType, bits, URNG>( return mult * r < limit ? sprout::random::detail::generate_canonical_impl_0_1<RealType, bits, URNG>(
r, limit, r, limit,
s + sprout::math::floor( s + sprout::math::floor(
(RealType(sprout::generators::generated_value(rnd)) - RealType(sprout::generators::next_generator(rnd).min())) * r (RealType(sprout::random::result(rnd)) - RealType(sprout::random::next(rnd).min())) * r
) * mult, ) * mult,
mult * r, mult * r,
rnd() rnd()
) )
: pair_type( : pair_type(
(s + sprout::math::floor( (s + sprout::math::floor(
(RealType(sprout::generators::generated_value(rnd)) - RealType(sprout::generators::next_generator(rnd).min())) * r (RealType(sprout::random::result(rnd)) - RealType(sprout::random::next(rnd).min())) * r
) * mult) / (mult * r), ) * mult) / (mult * r),
sprout::generators::next_generator(rnd) sprout::random::next(rnd)
) )
; ;
} }
@ -176,13 +176,13 @@ namespace sprout {
typedef sprout::pair<RealType, URNG> const pair_type; typedef sprout::pair<RealType, URNG> const pair_type;
return r < limit ? sprout::random::detail::generate_canonical_impl_0_1<RealType, bits, URNG>( return r < limit ? sprout::random::detail::generate_canonical_impl_0_1<RealType, bits, URNG>(
r, limit, r, limit,
RealType(sprout::generators::generated_value(rnd) - sprout::generators::next_generator(rnd).min()), RealType(sprout::random::result(rnd) - sprout::random::next(rnd).min()),
r, r,
rnd() rnd()
) )
: pair_type( : pair_type(
RealType(sprout::generators::generated_value(rnd) - sprout::generators::next_generator(rnd).min()) / r, RealType(sprout::random::result(rnd) - sprout::random::next(rnd).min()) / r,
sprout::generators::next_generator(rnd) sprout::random::next(rnd)
) )
; ;
} }

View file

@ -15,7 +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/random/result.hpp>
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
namespace sprout { namespace sprout {
@ -91,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) - sprout::generators::generated_value(rnd)) / log_1mp_)), static_cast<IntType>(sprout::math::floor(sprout::math::log(RealType(1) - sprout::random::result(rnd)) / log_1mp_)),
sprout::generators::next_generator(rnd).engine(), sprout::random::next(rnd).engine(),
*this *this
); );
} }

View file

@ -17,7 +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/random/result.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>
@ -212,8 +212,8 @@ namespace sprout {
template<typename EngineResult> template<typename EngineResult>
SPROUT_CONSTEXPR sprout::random::random_result<rand48> generate(EngineResult const& rnd) 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>(sprout::generators::generated_value(rnd)) >> 17, static_cast<result_type>(sprout::random::result(rnd)) >> 17,
rand48(sprout::generators::next_generator(rnd), private_construct_t()) rand48(sprout::random::next(rnd), private_construct_t())
); );
} }
public: public:

View file

@ -19,7 +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/random/result.hpp>
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
namespace sprout { namespace sprout {
@ -141,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(
sprout::generators::next_generator(rnd).engine(), r1, sprout::generators::generated_value(rnd), sprout::random::next(rnd).engine(), r1, sprout::random::result(rnd),
sprout::sqrt(-result_type(2) * sprout::math::log(result_type(1) - sprout::generators::generated_value(rnd))), true sprout::sqrt(-result_type(2) * sprout::math::log(result_type(1) - sprout::random::result(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>(sprout::generators::generated_value(rnd), sprout::generators::next_generator(rnd)()); return generate_1_1<Engine>(sprout::random::result(rnd), sprout::random::next(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

@ -98,6 +98,12 @@ namespace sprout {
SPROUT_CONSTEXPR result_type const& result() const SPROUT_NOEXCEPT { SPROUT_CONSTEXPR result_type const& result() const SPROUT_NOEXCEPT {
return result_; return result_;
} }
SPROUT_CXX14_CONSTEXPR generator_type& next() SPROUT_NOEXCEPT {
return generator_;
}
SPROUT_CONSTEXPR generator_type const& next() const SPROUT_NOEXCEPT {
return generator_;
}
SPROUT_CXX14_CONSTEXPR engine_type& engine() SPROUT_NOEXCEPT { SPROUT_CXX14_CONSTEXPR engine_type& engine() SPROUT_NOEXCEPT {
return generator_.engine(); return generator_.engine();
} }
@ -225,6 +231,12 @@ namespace sprout {
SPROUT_CONSTEXPR result_type const& result() const SPROUT_NOEXCEPT { SPROUT_CONSTEXPR result_type const& result() const SPROUT_NOEXCEPT {
return result_; return result_;
} }
SPROUT_CXX14_CONSTEXPR generator_type& next() SPROUT_NOEXCEPT {
return generator_;
}
SPROUT_CONSTEXPR generator_type const& next() const SPROUT_NOEXCEPT {
return generator_;
}
SPROUT_CXX14_CONSTEXPR engine_type& engine() SPROUT_NOEXCEPT { SPROUT_CXX14_CONSTEXPR engine_type& engine() SPROUT_NOEXCEPT {
return generator_; return generator_;
} }

42
sprout/random/result.hpp Normal file
View file

@ -0,0 +1,42 @@
/*=============================================================================
Copyright (c) 2011-2014 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef SPROUT_RANDOM_RESULT_HPP
#define SPROUT_RANDOM_RESULT_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/generator/functions.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
namespace random {
//
// result
//
template<typename T>
inline SPROUT_CONSTEXPR decltype(sprout::generators::generated_value(std::declval<T>()))
result(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generated_value(std::declval<T>())))
{
return sprout::generators::generated_value(sprout::forward<T>(t));
}
//
// next
//
template<typename T>
inline SPROUT_CONSTEXPR decltype(sprout::generators::next_generator(std::declval<T>()))
next(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::next_generator(std::declval<T>())))
{
return sprout::generators::next_generator(sprout::forward<T>(t));
}
} // namespace random
} // namespace sprout
#endif // #ifndef SPROUT_RANDOM_RESULT_HPP

View file

@ -24,7 +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/random/result.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>
@ -86,9 +86,9 @@ namespace sprout {
member_type member_type
>::type init_member_4(sprout::index_tuple<Indexes...>, sprout::array<result_type, M> const& a, EngineResult 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{
sprout::generators::next_generator(rnd), sprout::random::next(rnd),
sprout::array<result_type, k>{{a[Indexes]..., args...}}, sprout::array<result_type, k>{{a[Indexes]..., args...}},
sprout::generators::generated_value(rnd) sprout::random::result(rnd)
}; };
} }
template<std::size_t M, typename EngineResult, typename... Args> template<std::size_t M, typename EngineResult, typename... Args>
@ -103,7 +103,7 @@ namespace sprout {
(M + sizeof...(Args) < k), (M + sizeof...(Args) < k),
member_type member_type
>::type init_member_3(sprout::array<result_type, M> const& a, EngineResult 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, sprout::generators::next_generator(rnd)(), args..., sprout::generators::generated_value(rnd)); return init_member_3(a, sprout::random::next(rnd)(), args..., sprout::random::result(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) {
@ -116,9 +116,9 @@ namespace sprout {
member_type member_type
>::type init_member_1(EngineResult const& rnd, Args const&... args) { >::type init_member_1(EngineResult const& rnd, Args const&... args) {
return member_type{ return member_type{
sprout::generators::next_generator(rnd), sprout::random::next(rnd),
sprout::array<result_type, k>{{args...}}, sprout::array<result_type, k>{{args...}},
sprout::generators::generated_value(rnd) sprout::random::result(rnd)
}; };
} }
template<typename EngineResult, typename... Args> template<typename EngineResult, typename... Args>
@ -126,7 +126,7 @@ namespace sprout {
(sizeof...(Args) < k), (sizeof...(Args) < k),
member_type member_type
>::type init_member_1(EngineResult const& rnd, Args const&... args) { >::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)); return init_member_1(sprout::random::next(rnd)(), args..., sprout::random::result(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));
@ -156,8 +156,8 @@ namespace sprout {
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(
sprout::generators::next_generator(rnd), sprout::random::next(rnd),
sprout::fixed::set(v_, j, sprout::generators::generated_value(rnd)), sprout::fixed::set(v_, j, sprout::random::result(rnd)),
v_[j], v_[j],
private_construct_t() private_construct_t()
) )

View file

@ -13,7 +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> #include <sprout/random/result.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
@ -66,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>(sprout::generators::next_generator(rnd), sprout::generators::next_generator(rnd)()) : generate<D + 1>(sprout::random::next(rnd), sprout::random::next(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)>
@ -81,7 +81,7 @@ namespace sprout {
return generate_1<D + 1>( return generate_1<D + 1>(
eng, eng,
rnd, rnd,
result_type(sprout::generators::generated_value(rnd) - eng.min()) * ( result_type(sprout::random::result(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
@ -101,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(sprout::generators::next_generator(rnd), sprout::generators::next_generator(rnd)()) : generate(sprout::random::next(rnd), sprout::random::next(rnd)())
; ;
} }
template<typename Engine, typename EngineResult> template<typename Engine, typename EngineResult>
@ -111,7 +111,7 @@ namespace sprout {
return generate_1( return generate_1(
eng, eng,
rnd, rnd,
result_type(sprout::generators::generated_value(rnd) - eng.min()) * ( result_type(sprout::random::result(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,7 +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/random/result.hpp>
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
namespace sprout { namespace sprout {
@ -183,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>(
sprout::generators::next_generator(rnd), min_value, range, sprout::random::next(rnd), min_value, range,
bmin, brange, bucket_size, bmin, brange, bucket_size,
sprout::random::detail::subtract<BaseResult>()(sprout::generators::generated_value(rnd), bmin) / bucket_size sprout::random::detail::subtract<BaseResult>()(sprout::random::result(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)>
@ -329,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>()(sprout::generators::generated_value(rnd), bmin) * mult) result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(sprout::random::result(rnd), bmin) * mult)
), ),
sprout::generators::next_generator(rnd) sprout::random::next(rnd)
} }
: sprout::random::detail::generate_uniform_int_true_2_1<D + 1>( : sprout::random::detail::generate_uniform_int_true_2_1<D + 1>(
sprout::generators::next_generator(rnd), min_value, range, sprout::random::next(rnd), min_value, range,
bmin, brange, limit, bmin, brange, limit,
result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(sprout::generators::generated_value(rnd), bmin) * mult), result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(sprout::random::result(rnd), bmin) * mult),
mult * (RangeType(brange) + RangeType(1)) mult * (RangeType(brange) + RangeType(1))
) )
; ;
@ -423,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>()(sprout::generators::generated_value(rnd), bmin)), base_unsigned(sprout::random::detail::subtract<BaseResult>()(sprout::random::result(rnd), bmin)),
min_value min_value
), ),
sprout::generators::next_generator(rnd) sprout::random::next(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)>
@ -557,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(
sprout::generators::next_generator(rnd), min_value, range, sprout::random::next(rnd), min_value, range,
bmin, brange, bucket_size, bmin, brange, bucket_size,
sprout::random::detail::subtract<BaseResult>()(sprout::generators::generated_value(rnd), bmin) / bucket_size sprout::random::detail::subtract<BaseResult>()(sprout::random::result(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>
@ -645,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>()(sprout::generators::generated_value(rnd), bmin) * mult) result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(sprout::random::result(rnd), bmin) * mult)
), ),
sprout::generators::next_generator(rnd) sprout::random::next(rnd)
} }
: sprout::random::detail::generate_uniform_int_true_2_1( : sprout::random::detail::generate_uniform_int_true_2_1(
sprout::generators::next_generator(rnd), min_value, range, sprout::random::next(rnd), min_value, range,
bmin, brange, limit, bmin, brange, limit,
result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(sprout::generators::generated_value(rnd), bmin) * mult), result + static_cast<RangeType>(sprout::random::detail::subtract<BaseResult>()(sprout::random::result(rnd), bmin) * mult),
mult * (RangeType(brange) + RangeType(1)) mult * (RangeType(brange) + RangeType(1))
) )
; ;
@ -711,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>()(sprout::generators::generated_value(rnd), bmin)), base_unsigned(sprout::random::detail::subtract<BaseResult>()(sprout::random::result(rnd), bmin)),
min_value min_value
), ),
sprout::generators::next_generator(rnd) sprout::random::next(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,7 +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/random/result.hpp>
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
namespace sprout { namespace sprout {
@ -149,10 +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>(
sprout::generators::next_generator(rnd), sprout::random::next(rnd),
min_value, max_value, min_value, max_value,
static_cast<T>(sprout::generators::generated_value(rnd) - sprout::generators::next_generator(rnd).min()), static_cast<T>(sprout::random::result(rnd) - sprout::random::next(rnd).min()),
static_cast<T>(sprout::generators::next_generator(rnd).max() - sprout::generators::next_generator(rnd).min()) static_cast<T>(sprout::random::next(rnd).max() - sprout::random::next(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)>
@ -234,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>(
sprout::generators::next_generator(rnd), sprout::random::next(rnd),
min_value, max_value, min_value, max_value,
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>()(sprout::random::result(rnd), sprout::random::next(rnd).min())),
static_cast<T>(sprout::random::detail::subtract<base_result>()(sprout::generators::next_generator(rnd).max(), sprout::generators::next_generator(rnd).min())) + 1 static_cast<T>(sprout::random::detail::subtract<base_result>()(sprout::random::next(rnd).max(), sprout::random::next(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)>
@ -293,10 +293,10 @@ namespace sprout {
) )
{ {
return sprout::random::detail::generate_uniform_real_false_2( return sprout::random::detail::generate_uniform_real_false_2(
sprout::generators::next_generator(rnd), sprout::random::next(rnd),
min_value, max_value, min_value, max_value,
static_cast<T>(sprout::generators::generated_value(rnd) - sprout::generators::next_generator(rnd).min()), static_cast<T>(sprout::random::result(rnd) - sprout::random::next(rnd).min()),
static_cast<T>(sprout::generators::next_generator(rnd).max() - sprout::generators::next_generator(rnd).min()) static_cast<T>(sprout::random::next(rnd).max() - sprout::random::next(rnd).min())
); );
} }
template<typename EngineResult, typename T> template<typename EngineResult, typename T>
@ -343,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(
sprout::generators::next_generator(rnd), sprout::random::next(rnd),
min_value, max_value, min_value, max_value,
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>()(sprout::random::result(rnd), sprout::random::next(rnd).min())),
static_cast<T>(sprout::random::detail::subtract<base_result>()(sprout::generators::next_generator(rnd).max(), sprout::generators::next_generator(rnd).min())) + 1 static_cast<T>(sprout::random::detail::subtract<base_result>()(sprout::random::next(rnd).max(), sprout::random::next(rnd).min())) + 1
); );
} }
#endif #endif

View file

@ -16,7 +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/random/result.hpp>
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
namespace sprout { namespace sprout {
@ -136,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_),
sprout::generators::next_generator(rnd), sprout::random::next(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_),
sprout::generators::next_generator(rnd), sprout::random::next(rnd),
*this *this
) )
; ;
@ -160,7 +160,7 @@ namespace sprout {
rnd, rnd,
range, range,
base_range, base_range,
BaseUnsigned(sprout::random::detail::subtract<base_result>()(sprout::generators::generated_value(rnd), eng.min())) BaseUnsigned(sprout::random::detail::subtract<base_result>()(sprout::random::result(rnd), eng.min()))
); );
} }
template<typename Engine> template<typename Engine>
@ -190,12 +190,12 @@ namespace sprout {
return offset > range return offset > range
? sprout::random::random_result<Engine, uniform_smallint>( ? sprout::random::random_result<Engine, uniform_smallint>(
max_, max_,
sprout::generators::next_generator(rnd).engine(), sprout::random::next(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_),
sprout::generators::next_generator(rnd).engine(), sprout::random::next(rnd).engine(),
*this *this
) )
; ;
@ -212,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>(sprout::generators::generated_value(rnd) * (static_cast<base_result>(range) + 1)) static_cast<RangeType>(sprout::random::result(rnd) * (static_cast<base_result>(range) + 1))
); );
} }
template<class Engine> template<class Engine>

View file

@ -16,5 +16,6 @@
#include <sprout/random/generate_array.hpp> #include <sprout/random/generate_array.hpp>
#include <sprout/random/iterator.hpp> #include <sprout/random/iterator.hpp>
#include <sprout/random/range.hpp> #include <sprout/random/range.hpp>
#include <sprout/random/result.hpp>
#endif // #ifndef SPROUT_RANDOM_UTILITY_HPP #endif // #ifndef SPROUT_RANDOM_UTILITY_HPP

View file

@ -13,7 +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/random/result.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
@ -47,9 +47,9 @@ namespace sprout {
template<typename EngineResult1, typename EngineResult2> template<typename EngineResult1, typename EngineResult2>
SPROUT_CONSTEXPR sprout::random::random_result<xor_combine_engine> generate(EngineResult1 const& rnd1, EngineResult2 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>(
(sprout::generators::generated_value(rnd1) << s1) ^ (sprout::generators::generated_value(rnd2) << s2), (sprout::random::result(rnd1) << s1) ^ (sprout::random::result(rnd2) << s2),
xor_combine_engine( xor_combine_engine(
sprout::generators::next_generator(rnd1), sprout::generators::next_generator(rnd2) sprout::random::next(rnd1), sprout::random::next(rnd2)
) )
); );
} }

View file

@ -16,7 +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> #include <sprout/random/result.hpp>
namespace sprout { namespace sprout {
namespace uuids { namespace uuids {
@ -59,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..., sprout::generators::generated_value(rnd)); return random_to_uuid_1(args..., sprout::random::result(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(sprout::generators::next_generator(rnd)(), args..., sprout::generators::generated_value(rnd)); return random_to_uuid(sprout::random::next(rnd)(), args..., sprout::random::result(rnd));
} }
public: public:
SPROUT_CONSTEXPR basic_random_generator() SPROUT_CONSTEXPR basic_random_generator()