]> git.donarmstrong.com Git - rsem.git/blob - boost/random/detail/uniform_int_float.hpp
Added posterior standard deviation of counts as output if either '--calc-pme' or...
[rsem.git] / boost / random / detail / uniform_int_float.hpp
1 /* boost random/detail/uniform_int_float.hpp header file
2  *
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)
7  *
8  * See http://www.boost.org for most recent version including documentation.
9  *
10  * $Id: uniform_int_float.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $
11  *
12  */
13
14 #ifndef BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
15 #define BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
16
17 #include <boost/config.hpp>
18 #include <boost/random/detail/config.hpp>
19 #include <boost/random/uniform_01.hpp>
20
21
22 namespace boost {
23 namespace random {
24 namespace detail {
25
26 template<class UniformRandomNumberGenerator, class IntType = unsigned long>
27 class uniform_int_float
28 {
29 public:
30   typedef UniformRandomNumberGenerator base_type;
31   typedef IntType result_type;
32
33   uniform_int_float(base_type rng, IntType min_arg = 0, IntType max_arg = 0xffffffff)
34     : _rng(rng), _min(min_arg), _max(max_arg)
35   {
36     init();
37   }
38
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(); }
43
44   result_type operator()()
45   {
46     return static_cast<IntType>(_rng() * _range) + _min;
47   }
48
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)
53   {
54     os << ud._min << " " << ud._max;
55     return os;
56   }
57
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)
61   {
62     is >> std::ws >> ud._min >> std::ws >> ud._max;
63     ud.init();
64     return is;
65   }
66 #endif
67
68 private:
69   void init()
70   {
71     _range = static_cast<base_result>(_max-_min)+1;
72   }
73
74   typedef typename base_type::result_type base_result;
75   uniform_01<base_type> _rng;
76   result_type _min, _max;
77   base_result _range;
78 };
79
80
81 } // namespace detail
82 } // namespace random
83 } // namespace boost
84
85 #endif // BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP