1 /* boost random/detail/uniform_int_float.hpp header file
\r
3 * Copyright Jens Maurer 2000-2001
\r
4 * Distributed under the Boost Software License, Version 1.0. (See
\r
5 * accompanying file LICENSE_1_0.txt or copy at
\r
6 * http://www.boost.org/LICENSE_1_0.txt)
\r
8 * See http://www.boost.org for most recent version including documentation.
\r
10 * $Id: uniform_int_float.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $
\r
14 #ifndef BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
\r
15 #define BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
\r
17 #include <boost/config.hpp>
\r
18 #include <boost/random/detail/config.hpp>
\r
19 #include <boost/random/uniform_01.hpp>
\r
26 template<class UniformRandomNumberGenerator, class IntType = unsigned long>
\r
27 class uniform_int_float
\r
30 typedef UniformRandomNumberGenerator base_type;
\r
31 typedef IntType result_type;
\r
33 uniform_int_float(base_type rng, IntType min_arg = 0, IntType max_arg = 0xffffffff)
\r
34 : _rng(rng), _min(min_arg), _max(max_arg)
\r
39 result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; }
\r
40 result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; }
\r
41 base_type& base() { return _rng.base(); }
\r
42 const base_type& base() const { return _rng.base(); }
\r
44 result_type operator()()
\r
46 return static_cast<IntType>(_rng() * _range) + _min;
\r
49 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
\r
50 template<class CharT, class Traits>
\r
51 friend std::basic_ostream<CharT,Traits>&
\r
52 operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_int_float& ud)
\r
54 os << ud._min << " " << ud._max;
\r
58 template<class CharT, class Traits>
\r
59 friend std::basic_istream<CharT,Traits>&
\r
60 operator>>(std::basic_istream<CharT,Traits>& is, uniform_int_float& ud)
\r
62 is >> std::ws >> ud._min >> std::ws >> ud._max;
\r
71 _range = static_cast<base_result>(_max-_min)+1;
\r
74 typedef typename base_type::result_type base_result;
\r
75 uniform_01<base_type> _rng;
\r
76 result_type _min, _max;
\r
81 } // namespace detail
\r
82 } // namespace random
\r
83 } // namespace boost
\r
85 #endif // BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
\r