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