]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/random/detail/uniform_int_float.hpp
Logo AND Algorithmique Numérique Distribuée

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