1 /* boost random/detail/uniform_int_float.hpp header file
3 * Copyright Jens Maurer 2000-2001
4 * Copyright Steven Watanabe 2011
5 * Distributed under the Boost Software License, Version 1.0. (See
6 * accompanying file LICENSE_1_0.txt or copy at
7 * http://www.boost.org/LICENSE_1_0.txt)
9 * See http://www.boost.org for most recent version including documentation.
15 #ifndef BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
16 #define BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
18 #include <boost/limits.hpp>
19 #include <boost/config.hpp>
20 #include <boost/integer.hpp>
21 #include <boost/random/detail/config.hpp>
22 #include <boost/random/detail/generator_bits.hpp>
24 #include <boost/random/detail/disable_warnings.hpp>
31 class uniform_int_float
34 typedef URNG base_type;
35 typedef typename base_type::result_type base_result;
37 typedef typename boost::uint_t<
38 (std::numeric_limits<boost::uintmax_t>::digits <
39 std::numeric_limits<base_result>::digits)?
40 std::numeric_limits<boost::uintmax_t>::digits :
41 std::numeric_limits<base_result>::digits
44 uniform_int_float(base_type& rng)
47 static result_type min BOOST_PREVENT_MACRO_SUBSTITUTION ()
49 static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
51 std::size_t digits = std::numeric_limits<result_type>::digits;
52 if(detail::generator_bits<URNG>::value() < digits) {
53 digits = detail::generator_bits<URNG>::value();
55 return (result_type(2) << (digits - 1)) - 1;
57 base_type& base() { return _rng; }
58 const base_type& base() const { return _rng; }
60 result_type operator()()
62 base_result range = static_cast<base_result>((max)())+1;
63 return static_cast<result_type>(_rng() * range);
74 #include <boost/random/detail/enable_warnings.hpp>
76 #endif // BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP