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

Private GIT Repository
e4e6d566963aa42081dce6c33a5b9ae67e842278
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / random / additive_combine.hpp
1 /* boost random/additive_combine.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: additive_combine.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $\r
11  *\r
12  * Revision history\r
13  *  2001-02-18  moved to individual header files\r
14  */\r
15 \r
16 #ifndef BOOST_RANDOM_ADDITIVE_COMBINE_HPP\r
17 #define BOOST_RANDOM_ADDITIVE_COMBINE_HPP\r
18 \r
19 #include <iostream>\r
20 #include <algorithm> // for std::min and std::max\r
21 #include <boost/config.hpp>\r
22 #include <boost/cstdint.hpp>\r
23 #include <boost/random/detail/config.hpp>\r
24 #include <boost/random/linear_congruential.hpp>\r
25 \r
26 namespace boost {\r
27 namespace random {\r
28 \r
29 // L'Ecuyer 1988\r
30 template<class MLCG1, class MLCG2,\r
31 #ifndef BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS\r
32   typename MLCG1::result_type \r
33 #else\r
34   int32_t\r
35 #endif\r
36   val>\r
37 class additive_combine\r
38 {\r
39 public:\r
40   typedef MLCG1 first_base;\r
41   typedef MLCG2 second_base;\r
42   typedef typename MLCG1::result_type result_type;\r
43 #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION\r
44   static const bool has_fixed_range = true;\r
45   static const result_type min_value = 1;\r
46   static const result_type max_value = MLCG1::max_value-1;\r
47 #else\r
48   enum { has_fixed_range = false };\r
49 #endif\r
50   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 1; }\r
51   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_mlcg1.max)()-1; }\r
52 \r
53   additive_combine() : _mlcg1(), _mlcg2() { }\r
54   additive_combine(typename MLCG1::result_type seed1, \r
55                    typename MLCG2::result_type seed2)\r
56     : _mlcg1(seed1), _mlcg2(seed2) { }\r
57   additive_combine(result_type aseed)\r
58     : _mlcg1(aseed), _mlcg2(aseed) { }\r
59   template<class It> additive_combine(It& first, It last)\r
60     : _mlcg1(first, last), _mlcg2(first, last) { }\r
61 \r
62   void seed()\r
63   {\r
64     _mlcg1.seed();\r
65     _mlcg2.seed();\r
66   }\r
67 \r
68   void seed(result_type aseed)\r
69   {\r
70     _mlcg1.seed(aseed);\r
71     _mlcg2.seed(aseed);\r
72   }\r
73 \r
74   void seed(typename MLCG1::result_type seed1,\r
75             typename MLCG2::result_type seed2)\r
76   {\r
77     _mlcg1.seed(seed1);\r
78     _mlcg2.seed(seed2);\r
79   }\r
80 \r
81   template<class It> void seed(It& first, It last)\r
82   {\r
83     _mlcg1.seed(first, last);\r
84     _mlcg2.seed(first, last);\r
85   }\r
86 \r
87   result_type operator()() {\r
88     result_type z = _mlcg1() - _mlcg2();\r
89     if(z < 1)\r
90       z += MLCG1::modulus-1;\r
91     return z;\r
92   }\r
93   static bool validation(result_type x) { return val == x; }\r
94 \r
95 #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE\r
96 \r
97 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS\r
98   template<class CharT, class Traits>\r
99   friend std::basic_ostream<CharT,Traits>&\r
100   operator<<(std::basic_ostream<CharT,Traits>& os, const additive_combine& r)\r
101   { os << r._mlcg1 << " " << r._mlcg2; return os; }\r
102 \r
103   template<class CharT, class Traits>\r
104   friend std::basic_istream<CharT,Traits>&\r
105   operator>>(std::basic_istream<CharT,Traits>& is, additive_combine& r)\r
106   { is >> r._mlcg1 >> std::ws >> r._mlcg2; return is; }\r
107 #endif\r
108 \r
109   friend bool operator==(const additive_combine& x, const additive_combine& y)\r
110   { return x._mlcg1 == y._mlcg1 && x._mlcg2 == y._mlcg2; }\r
111   friend bool operator!=(const additive_combine& x, const additive_combine& y)\r
112   { return !(x == y); }\r
113 #else\r
114   // Use a member function; Streamable concept not supported.\r
115   bool operator==(const additive_combine& rhs) const\r
116   { return _mlcg1 == rhs._mlcg1 && _mlcg2 == rhs._mlcg2; }\r
117   bool operator!=(const additive_combine& rhs) const\r
118   { return !(*this == rhs); }\r
119 #endif\r
120 private:\r
121   MLCG1 _mlcg1;\r
122   MLCG2 _mlcg2;\r
123 };\r
124 \r
125 } // namespace random\r
126 \r
127 typedef random::additive_combine<\r
128     random::linear_congruential<int32_t, 40014, 0, 2147483563, 0>,\r
129     random::linear_congruential<int32_t, 40692, 0, 2147483399, 0>,\r
130   2060321752> ecuyer1988;\r
131 \r
132 } // namespace boost\r
133 \r
134 #endif // BOOST_RANDOM_ADDITIVE_COMBINE_HPP\r