/*============================================================================= Copyright (c) 2011-2013 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_DETAIL_UNIFORM_INT_FLOAT_HPP #define SPROUT_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP #include #include #include #include #include #include #include #include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT namespace sprout { namespace random { namespace detail { template class uniform_int_float { public: typedef URNG base_type; typedef typename base_type::result_type base_result; typedef typename sprout::detail::uint_t< (sprout::numeric_limits::digits < sprout::numeric_limits::digits) ? sprout::numeric_limits::digits : sprout::numeric_limits::digits >::fast result_type; private: base_type rng_; public: SPROUT_CONSTEXPR uniform_int_float() : rng_() {} explicit SPROUT_CONSTEXPR uniform_int_float(base_type const& rng) : rng_(rng) {} SPROUT_CONSTEXPR result_type min() const { return 0; } SPROUT_CONSTEXPR result_type max() const { return ( result_type(2) << ( NS_SSCRISK_CEL_OR_SPROUT::min( sprout::numeric_limits::digits, sprout::random::detail::generator_bits::value() ) - 1 ) ) - 1 ; } base_type& base() { return rng_; } SPROUT_CONSTEXPR base_type const& base() const { return rng_; } SPROUT_CONSTEXPR sprout::random::random_result generate( sprout::random::random_result const& rnd ) const { return sprout::random::random_result( static_cast(rnd.result() * (static_cast(max()) + 1)), uniform_int_float(rnd.engine()) ); } SPROUT_CONSTEXPR sprout::random::random_result operator()() const { return generate(rng_()); } }; } // namespace detail } // namespace random } // namespace sprout #endif // #ifndef SPROUT_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP