os/ossrv/ossrv_pub/boost_apis/boost/tr1/random.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/tr1/random.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,581 @@
     1.4 +//  (C) Copyright John Maddock 2005.
     1.5 +//  (C) Copyright Henry S. Warren 2005.
     1.6 +//  Use, modification and distribution are subject to the
     1.7 +//  Boost Software License, Version 1.0. (See accompanying file
     1.8 +//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     1.9 +
    1.10 +#ifndef BOOST_TR1_RANDOM_HPP_INCLUDED
    1.11 +#  define BOOST_TR1_RANDOM_HPP_INCLUDED
    1.12 +#  include <boost/tr1/detail/config.hpp>
    1.13 +
    1.14 +#ifdef BOOST_HAS_TR1_RANDOM
    1.15 +#  include BOOST_TR1_HEADER(random)
    1.16 +#else
    1.17 +// Boost.Random:
    1.18 +#include <boost/random.hpp>
    1.19 +#ifndef __SUNPRO_CC
    1.20 +    // Sunpros linker complains if we so much as include this...
    1.21 +#   include <boost/nondet_random.hpp>
    1.22 +#endif
    1.23 +#include <boost/tr1/detail/functor2iterator.hpp>
    1.24 +#include <boost/type_traits/is_fundamental.hpp>
    1.25 +#include <boost/type_traits/is_same.hpp>
    1.26 +
    1.27 +namespace std { namespace tr1{
    1.28 +
    1.29 +using ::boost::variate_generator;
    1.30 +
    1.31 +template<class UIntType, UIntType a, UIntType c, UIntType m>
    1.32 +class linear_congruential
    1.33 +{
    1.34 +private:
    1.35 +   typedef ::boost::random::linear_congruential<UIntType, a, c, m, 0> impl_type;
    1.36 +public:
    1.37 +   // types
    1.38 +   typedef UIntType result_type;
    1.39 +   // parameter values
    1.40 +   BOOST_STATIC_CONSTANT(UIntType, multiplier = a);
    1.41 +   BOOST_STATIC_CONSTANT(UIntType, increment = c);
    1.42 +   BOOST_STATIC_CONSTANT(UIntType, modulus = m);
    1.43 +   // constructors and member function
    1.44 +   explicit linear_congruential(unsigned long x0 = 1)
    1.45 +      : m_gen(x0){}
    1.46 +   linear_congruential(const linear_congruential& that)
    1.47 +      : m_gen(that.m_gen){}
    1.48 +   template<class Gen> linear_congruential(Gen& g)
    1.49 +   {
    1.50 +      init1(g, ::boost::is_same<Gen,linear_congruential>());
    1.51 +   }
    1.52 +   void seed(unsigned long x0 = 1)
    1.53 +   { m_gen.seed(x0); }
    1.54 +   template<class Gen> void seed(Gen& g)
    1.55 +   { 
    1.56 +      init2(g, ::boost::is_fundamental<Gen>());
    1.57 +   }
    1.58 +   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION() const
    1.59 +   { return (m_gen.min)(); }
    1.60 +   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION() const
    1.61 +   { return (m_gen.max)(); }
    1.62 +   result_type operator()()
    1.63 +   {
    1.64 +      return m_gen(); 
    1.65 +   }
    1.66 +   bool operator==(const linear_congruential& that)const
    1.67 +   { return m_gen == that.m_gen; }
    1.68 +   bool operator!=(const linear_congruential& that)const
    1.69 +   { return m_gen != that.m_gen; }
    1.70 +
    1.71 +#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
    1.72 +  template<class CharT, class Traits>
    1.73 +  friend std::basic_ostream<CharT,Traits>&
    1.74 +  operator<<(std::basic_ostream<CharT,Traits>& os,
    1.75 +             const linear_congruential& lcg)
    1.76 +  {
    1.77 +    return os << lcg.m_gen; 
    1.78 +  }
    1.79 +
    1.80 +  template<class CharT, class Traits>
    1.81 +  friend std::basic_istream<CharT,Traits>&
    1.82 +  operator>>(std::basic_istream<CharT,Traits>& is,
    1.83 +             linear_congruential& lcg)
    1.84 +  {
    1.85 +    return is >> lcg.m_gen;
    1.86 +  }
    1.87 +#endif
    1.88 +
    1.89 +private:
    1.90 +   template <class Gen>
    1.91 +   void init1(Gen& g, const ::boost::true_type&)
    1.92 +   {
    1.93 +      m_gen = g.m_gen;
    1.94 +   }
    1.95 +   template <class Gen>
    1.96 +   void init1(Gen& g, const ::boost::false_type&)
    1.97 +   {
    1.98 +      init2(g, ::boost::is_fundamental<Gen>());
    1.99 +   }
   1.100 +   template <class Gen>
   1.101 +   void init2(Gen& g, const ::boost::true_type&)
   1.102 +   {
   1.103 +      m_gen.seed(static_cast<unsigned long>(g));
   1.104 +   }
   1.105 +   template <class Gen>
   1.106 +   void init2(Gen& g, const ::boost::false_type&)
   1.107 +   {
   1.108 +      //typedef typename Gen::result_type gen_rt;
   1.109 +      boost::tr1_details::functor2iterator<Gen, unsigned long> f1(g), f2;
   1.110 +      m_gen.seed(f1, f2);
   1.111 +   }
   1.112 +   impl_type m_gen;
   1.113 +};
   1.114 +
   1.115 +template<class UIntType, int w, int n, int m, int r,
   1.116 +UIntType a, int u, int s, UIntType b, int t, UIntType c, int l>
   1.117 +class mersenne_twister
   1.118 +{
   1.119 +   typedef ::boost::random::mersenne_twister
   1.120 +      <UIntType, w, n, m, r, a, u, s, b, t, c, l, 0> imp_type;
   1.121 +public:
   1.122 +   // types
   1.123 +   typedef UIntType result_type;
   1.124 +   // parameter values
   1.125 +   BOOST_STATIC_CONSTANT(int, word_size = w);
   1.126 +   BOOST_STATIC_CONSTANT(int, state_size = n);
   1.127 +   BOOST_STATIC_CONSTANT(int, shift_size = m);
   1.128 +   BOOST_STATIC_CONSTANT(int, mask_bits = r);
   1.129 +   BOOST_STATIC_CONSTANT(UIntType, parameter_a = a);
   1.130 +   BOOST_STATIC_CONSTANT(int, output_u = u);
   1.131 +   BOOST_STATIC_CONSTANT(int, output_s = s);
   1.132 +   BOOST_STATIC_CONSTANT(UIntType, output_b = b);
   1.133 +   BOOST_STATIC_CONSTANT(int, output_t = t);
   1.134 +   BOOST_STATIC_CONSTANT(UIntType, output_c = c);
   1.135 +   BOOST_STATIC_CONSTANT(int, output_l = l);
   1.136 +   // constructors and member function
   1.137 +   mersenne_twister(){}
   1.138 +   explicit mersenne_twister(unsigned long value)
   1.139 +      : m_gen(value == 0 ? 4357UL : value){}
   1.140 +   template<class Gen> mersenne_twister(Gen& g)
   1.141 +   {
   1.142 +      init1(g, ::boost::is_same<mersenne_twister,Gen>());
   1.143 +   }
   1.144 +   void seed()
   1.145 +   { m_gen.seed(); }
   1.146 +   void seed(unsigned long value)
   1.147 +   { m_gen.seed(value == 0 ? 5489UL : value); }
   1.148 +   template<class Gen> void seed(Gen& g)
   1.149 +   { init2(g, ::boost::is_fundamental<Gen>()); }
   1.150 +   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION() const
   1.151 +   { return (m_gen.min)(); }
   1.152 +   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION() const
   1.153 +   { return (m_gen.max)(); }
   1.154 +   result_type operator()()
   1.155 +   { return m_gen(); }
   1.156 +   bool operator==(const mersenne_twister& that)const
   1.157 +   { return m_gen == that.m_gen; }
   1.158 +   bool operator!=(const mersenne_twister& that)const
   1.159 +   { return m_gen != that.m_gen; }
   1.160 +
   1.161 +#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
   1.162 +   template<class CharT, class Traits>
   1.163 +   friend std::basic_ostream<CharT,Traits>&
   1.164 +   operator<<(std::basic_ostream<CharT,Traits>& os,
   1.165 +            const mersenne_twister& lcg)
   1.166 +   {
   1.167 +      return os << lcg.m_gen;
   1.168 +   }
   1.169 +
   1.170 +   template<class CharT, class Traits>
   1.171 +   friend std::basic_istream<CharT,Traits>&
   1.172 +   operator>>(std::basic_istream<CharT,Traits>& is,
   1.173 +            mersenne_twister& lcg)
   1.174 +   {
   1.175 +      return is >> lcg.m_gen;
   1.176 +   }
   1.177 +#endif
   1.178 +private:
   1.179 +   template <class Gen>
   1.180 +   void init1(Gen& g, const ::boost::true_type&)
   1.181 +   {
   1.182 +      m_gen = g.m_gen;
   1.183 +   }
   1.184 +   template <class Gen>
   1.185 +   void init1(Gen& g, const ::boost::false_type&)
   1.186 +   {
   1.187 +      init2(g, ::boost::is_fundamental<Gen>());
   1.188 +   }
   1.189 +   template <class Gen>
   1.190 +   void init2(Gen& g, const ::boost::true_type&)
   1.191 +   {
   1.192 +      m_gen.seed(static_cast<unsigned long>(g == 0 ? 4357UL : g));
   1.193 +   }
   1.194 +   template <class Gen>
   1.195 +   void init2(Gen& g, const ::boost::false_type&)
   1.196 +   {
   1.197 +      m_gen.seed(g);
   1.198 +   }
   1.199 +   imp_type m_gen;
   1.200 +};
   1.201 +
   1.202 +template<class IntType, IntType m, int s, int r>
   1.203 +class subtract_with_carry
   1.204 +{
   1.205 +public:
   1.206 +   // types
   1.207 +   typedef IntType result_type;
   1.208 +   // parameter values
   1.209 +   BOOST_STATIC_CONSTANT(IntType, modulus = m);
   1.210 +   BOOST_STATIC_CONSTANT(int, long_lag = r);
   1.211 +   BOOST_STATIC_CONSTANT(int, short_lag = s);
   1.212 +
   1.213 +   // constructors and member function
   1.214 +   subtract_with_carry(){}
   1.215 +   explicit subtract_with_carry(unsigned long value)
   1.216 +      : m_gen(value == 0 ? 19780503UL : value){}
   1.217 +   template<class Gen> subtract_with_carry(Gen& g)
   1.218 +   { init1(g, ::boost::is_same<Gen, subtract_with_carry<IntType, m, s, r> >()); }
   1.219 +   void seed(unsigned long value = 19780503ul)
   1.220 +   { m_gen.seed(value == 0 ? 19780503UL : value); }
   1.221 +   template<class Gen> void seed(Gen& g)
   1.222 +   { init2(g, ::boost::is_fundamental<Gen>()); }
   1.223 +   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION() const
   1.224 +   { return (m_gen.min)(); }
   1.225 +   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION() const
   1.226 +   { return (m_gen.max)(); }
   1.227 +   result_type operator()()
   1.228 +   { return m_gen(); }
   1.229 +   bool operator==(const subtract_with_carry& that)const
   1.230 +   { return m_gen == that.m_gen; }
   1.231 +   bool operator!=(const subtract_with_carry& that)const
   1.232 +   { return m_gen != that.m_gen; }
   1.233 +
   1.234 +#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
   1.235 +   template<class CharT, class Traits>
   1.236 +   friend std::basic_ostream<CharT,Traits>&
   1.237 +   operator<<(std::basic_ostream<CharT,Traits>& os,
   1.238 +            const subtract_with_carry& lcg)
   1.239 +   {
   1.240 +      return os << lcg.m_gen;
   1.241 +   }
   1.242 +
   1.243 +   template<class CharT, class Traits>
   1.244 +   friend std::basic_istream<CharT,Traits>&
   1.245 +   operator>>(std::basic_istream<CharT,Traits>& is,
   1.246 +            subtract_with_carry& lcg)
   1.247 +   {
   1.248 +      return is >> lcg.m_gen;
   1.249 +   }
   1.250 +#endif
   1.251 +private:
   1.252 +   template <class Gen>
   1.253 +   void init1(Gen& g, const ::boost::true_type&)
   1.254 +   {
   1.255 +      m_gen = g.m_gen;
   1.256 +   }
   1.257 +   template <class Gen>
   1.258 +   void init1(Gen& g, const ::boost::false_type&)
   1.259 +   {
   1.260 +      init2(g, ::boost::is_fundamental<Gen>());
   1.261 +   }
   1.262 +   template <class Gen>
   1.263 +   void init2(Gen& g, const ::boost::true_type&)
   1.264 +   {
   1.265 +      m_gen.seed(static_cast<unsigned long>(g == 0 ? 19780503UL : g));
   1.266 +   }
   1.267 +   template <class Gen>
   1.268 +   void init2(Gen& g, const ::boost::false_type&)
   1.269 +   {
   1.270 +      m_gen.seed(g);
   1.271 +   }
   1.272 +   ::boost::random::subtract_with_carry<IntType, m, s, r, 0> m_gen;
   1.273 +};
   1.274 +
   1.275 +template<class RealType, int w, int s, int r>
   1.276 +class subtract_with_carry_01
   1.277 +{
   1.278 +public:
   1.279 +   // types
   1.280 +   typedef RealType result_type;
   1.281 +   // parameter values
   1.282 +   BOOST_STATIC_CONSTANT(int, word_size = w);
   1.283 +   BOOST_STATIC_CONSTANT(int, long_lag = r);
   1.284 +   BOOST_STATIC_CONSTANT(int, short_lag = s);
   1.285 +
   1.286 +   // constructors and member function
   1.287 +   subtract_with_carry_01(){}
   1.288 +   explicit subtract_with_carry_01(unsigned long value)
   1.289 +      : m_gen(value == 0 ? 19780503UL : value){}
   1.290 +   template<class Gen> subtract_with_carry_01(Gen& g)
   1.291 +   { init1(g, ::boost::is_same<Gen, subtract_with_carry_01<RealType, w, s, r> >()); }
   1.292 +   void seed(unsigned long value = 19780503UL)
   1.293 +   { m_gen.seed(value == 0 ? 19780503UL : value); }
   1.294 +   template<class Gen> void seed(Gen& g)
   1.295 +   { init2(g, ::boost::is_fundamental<Gen>()); }
   1.296 +   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION() const
   1.297 +   { return (m_gen.min)(); }
   1.298 +   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION() const
   1.299 +   { return (m_gen.max)(); }
   1.300 +   result_type operator()()
   1.301 +   { return m_gen(); }
   1.302 +   bool operator==(const subtract_with_carry_01& that)const
   1.303 +   { return m_gen == that.m_gen; }
   1.304 +   bool operator!=(const subtract_with_carry_01& that)const
   1.305 +   { return m_gen != that.m_gen; }
   1.306 +
   1.307 +#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
   1.308 +   template<class CharT, class Traits>
   1.309 +   friend std::basic_ostream<CharT,Traits>&
   1.310 +   operator<<(std::basic_ostream<CharT,Traits>& os,
   1.311 +            const subtract_with_carry_01& lcg)
   1.312 +   {
   1.313 +      return os << lcg.m_gen;
   1.314 +   }
   1.315 +
   1.316 +   template<class CharT, class Traits>
   1.317 +   friend std::basic_istream<CharT,Traits>&
   1.318 +   operator>>(std::basic_istream<CharT,Traits>& is,
   1.319 +            subtract_with_carry_01& lcg)
   1.320 +   {
   1.321 +      return is >> lcg.m_gen;
   1.322 +   }
   1.323 +#endif
   1.324 +private:
   1.325 +   template <class Gen>
   1.326 +   void init1(Gen& g, const ::boost::true_type&)
   1.327 +   {
   1.328 +      m_gen = g.m_gen;
   1.329 +   }
   1.330 +   template <class Gen>
   1.331 +   void init1(Gen& g, const ::boost::false_type&)
   1.332 +   {
   1.333 +      init2(g, ::boost::is_fundamental<Gen>());
   1.334 +   }
   1.335 +   template <class Gen>
   1.336 +   void init2(Gen& g, const ::boost::true_type&)
   1.337 +   {
   1.338 +      m_gen.seed(static_cast<unsigned long>(g == 0 ? 19780503UL : g));
   1.339 +   }
   1.340 +   template <class Gen>
   1.341 +   void init2(Gen& g, const ::boost::false_type&)
   1.342 +   {
   1.343 +      //typedef typename Gen::result_type gen_rt;
   1.344 +      boost::tr1_details::functor2iterator<Gen, unsigned long> f1(g), f2;
   1.345 +      m_gen.seed(f1, f2);
   1.346 +   }
   1.347 +   ::boost::random::subtract_with_carry_01<RealType, w, s, r, 0> m_gen;
   1.348 +};
   1.349 +
   1.350 +using ::boost::random::discard_block;
   1.351 +
   1.352 +template<class UniformRandomNumberGenerator1, int s1, class UniformRandomNumberGenerator2, int s2>
   1.353 +class xor_combine
   1.354 +{
   1.355 +public:
   1.356 +   // types
   1.357 +   typedef UniformRandomNumberGenerator1 base1_type;
   1.358 +   typedef UniformRandomNumberGenerator2 base2_type;
   1.359 +   typedef unsigned long result_type;
   1.360 +   // parameter values
   1.361 +   BOOST_STATIC_CONSTANT(int, shift1 = s1);
   1.362 +   BOOST_STATIC_CONSTANT(int, shift2 = s2);
   1.363 +   // constructors and member function
   1.364 +   xor_combine(){ init_minmax(); }
   1.365 +   xor_combine(const base1_type & rng1, const base2_type & rng2)
   1.366 +      : m_b1(rng1), m_b2(rng2) { init_minmax(); }
   1.367 +   xor_combine(unsigned long s)
   1.368 +      : m_b1(s), m_b2(s+1) { init_minmax(); }
   1.369 +   template<class Gen> xor_combine(Gen& g)
   1.370 +   { 
   1.371 +      init_minmax(); 
   1.372 +      init1(g, ::boost::is_same<Gen, xor_combine<UniformRandomNumberGenerator1, s1, UniformRandomNumberGenerator2, s2> >());
   1.373 +   }
   1.374 +   void seed()
   1.375 +   {
   1.376 +      m_b1.seed();
   1.377 +      m_b2.seed();
   1.378 +   }
   1.379 +   void seed(unsigned long s)
   1.380 +   {
   1.381 +      m_b1.seed(s);
   1.382 +      m_b2.seed(s+1);
   1.383 +   }
   1.384 +   template<class Gen> void seed(Gen& g)
   1.385 +   {
   1.386 +      init2(g, ::boost::is_fundamental<Gen>());
   1.387 +   }
   1.388 +
   1.389 +   const base1_type& base1() const
   1.390 +   { return m_b1; }
   1.391 +   const base2_type& base2() const
   1.392 +   { return m_b2; }
   1.393 +   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION() const
   1.394 +   { return m_min; }
   1.395 +   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION() const
   1.396 +   { return m_max; }
   1.397 +   result_type operator()()
   1.398 +   { return (m_b1() << s1) ^ (m_b2() << s2); }
   1.399 +
   1.400 +   bool operator == (const xor_combine& that)const
   1.401 +   { return (m_b1 == that.m_b1) && (m_b2 == that.m_b2); }
   1.402 +   bool operator != (const xor_combine& that)const
   1.403 +   { return !(*this == that); }
   1.404 +
   1.405 +#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
   1.406 +   template<class CharT, class Traits>
   1.407 +   friend std::basic_ostream<CharT,Traits>&
   1.408 +   operator<<(std::basic_ostream<CharT,Traits>& os,
   1.409 +            const xor_combine& lcg)
   1.410 +   {
   1.411 +      return os << lcg.m_b1 << " " << lcg.m_b2;
   1.412 +   }
   1.413 +
   1.414 +   template<class CharT, class Traits>
   1.415 +   friend std::basic_istream<CharT,Traits>&
   1.416 +   operator>>(std::basic_istream<CharT,Traits>& is,
   1.417 +            xor_combine& lcg)
   1.418 +   {
   1.419 +      return is >> lcg.m_b1 >> lcg.m_b2;
   1.420 +   }
   1.421 +#endif
   1.422 +
   1.423 +private:
   1.424 +   void init_minmax();
   1.425 +   base1_type m_b1;
   1.426 +   base2_type m_b2;
   1.427 +   result_type m_min;
   1.428 +   result_type m_max;
   1.429 +
   1.430 +   template <class Gen>
   1.431 +   void init1(Gen& g, const ::boost::true_type&)
   1.432 +   {
   1.433 +      m_b1 = g.m_b1;
   1.434 +      m_b2 = g.m_b2;
   1.435 +   }
   1.436 +   template <class Gen>
   1.437 +   void init1(Gen& g, const ::boost::false_type&)
   1.438 +   {
   1.439 +      init2(g, ::boost::is_fundamental<Gen>());
   1.440 +   }
   1.441 +   template <class Gen>
   1.442 +   void init2(Gen& g, const ::boost::true_type&)
   1.443 +   {
   1.444 +      m_b1.seed(static_cast<unsigned long>(g));
   1.445 +      m_b2.seed(static_cast<unsigned long>(g));
   1.446 +   }
   1.447 +   template <class Gen>
   1.448 +   void init2(Gen& g, const ::boost::false_type&)
   1.449 +   {
   1.450 +      m_b1.seed(g);
   1.451 +      m_b2.seed(g);
   1.452 +   }
   1.453 +};
   1.454 +
   1.455 +template<class UniformRandomNumberGenerator1, int s1, class UniformRandomNumberGenerator2, int s2>
   1.456 +void xor_combine<UniformRandomNumberGenerator1, s1, UniformRandomNumberGenerator2, s2>::init_minmax()
   1.457 +{
   1.458 +   //
   1.459 +   // The following code is based on that given in "Hacker's Delight"
   1.460 +   // by Henry S. Warren, (Addison-Wesley, 2003), and at 
   1.461 +   // http://www.hackersdelight.org/index.htm.
   1.462 +   // Used here by permission.
   1.463 +   //
   1.464 +   // calculation of minimum value:
   1.465 +   //
   1.466 +   result_type a = (m_b1.min)() << s1;
   1.467 +   result_type b = (m_b1.max)() << s1;
   1.468 +   result_type c = (m_b2.min)() << s2;
   1.469 +   result_type d = (m_b2.max)() << s2;
   1.470 +   result_type m, temp;
   1.471 +
   1.472 +   m = 0x1uL << ((sizeof(result_type) * CHAR_BIT) - 1);
   1.473 +   while (m != 0) {
   1.474 +      if (~a & c & m) {
   1.475 +         temp = (a | m) & (static_cast<result_type>(0u) - m);
   1.476 +         if (temp <= b) a = temp;
   1.477 +      }
   1.478 +      else if (a & ~c & m) {
   1.479 +         temp = (c | m) & (static_cast<result_type>(0u) - m);
   1.480 +         if (temp <= d) c = temp;
   1.481 +      }
   1.482 +      m >>= 1;
   1.483 +   }
   1.484 +   m_min = a ^ c;
   1.485 +
   1.486 +   //
   1.487 +   // calculation of maximum value:
   1.488 +   //
   1.489 +   if((((std::numeric_limits<result_type>::max)() >> s1) < (m_b1.max)())
   1.490 +      || ((((std::numeric_limits<result_type>::max)()) >> s2) < (m_b2.max)()))
   1.491 +   {
   1.492 +      m_max = (std::numeric_limits<result_type>::max)();
   1.493 +      return;
   1.494 +   }
   1.495 +   a = (m_b1.min)() << s1;
   1.496 +   b = (m_b1.max)() << s1;
   1.497 +   c = (m_b2.min)() << s2;
   1.498 +   d = (m_b2.max)() << s2;
   1.499 +
   1.500 +   m = 0x1uL << ((sizeof(result_type) * CHAR_BIT) - 1);
   1.501 +
   1.502 +   while (m != 0) {
   1.503 +      if (b & d & m) {
   1.504 +         temp = (b - m) | (m - 1);
   1.505 +         if (temp >= a) b = temp;
   1.506 +         else {
   1.507 +            temp = (d - m) | (m - 1);
   1.508 +            if (temp >= c) d = temp;
   1.509 +         }
   1.510 +      }
   1.511 +      m = m >> 1;
   1.512 +   }
   1.513 +   m_max = b ^ d;
   1.514 +}
   1.515 +
   1.516 +typedef linear_congruential< ::boost::int32_t, 16807, 0, 2147483647> minstd_rand0;
   1.517 +typedef linear_congruential< ::boost::int32_t, 48271, 0, 2147483647> minstd_rand;
   1.518 +typedef mersenne_twister< ::boost::uint32_t, 32,624,397,31,0x9908b0df,11,7,0x9d2c5680,15,0xefc60000,18> mt19937;
   1.519 +typedef subtract_with_carry_01<float, 24, 10, 24> ranlux_base_01;
   1.520 +typedef subtract_with_carry_01<double, 48, 10, 24> ranlux64_base_01;
   1.521 +typedef discard_block<subtract_with_carry< ::boost::int32_t, (1<<24), 10, 24>, 223, 24> ranlux3;
   1.522 +typedef discard_block<subtract_with_carry< ::boost::int32_t, (1<<24), 10, 24>, 389, 24> ranlux4;
   1.523 +typedef discard_block<subtract_with_carry_01<float, 24, 10, 24>, 223, 24> ranlux3_01;
   1.524 +typedef discard_block<subtract_with_carry_01<float, 24, 10, 24>, 389, 24> ranlux4_01;
   1.525 +
   1.526 +#ifndef __SUNPRO_CC
   1.527 +using ::boost::random_device;
   1.528 +#endif
   1.529 +using ::boost::uniform_int;
   1.530 +
   1.531 +class bernoulli_distribution
   1.532 +{
   1.533 +public:
   1.534 +   // types
   1.535 +   typedef int input_type;
   1.536 +   typedef bool result_type;
   1.537 +   // constructors and member function
   1.538 +   explicit bernoulli_distribution(double p = 0.5)
   1.539 +      : m_dist(p){}
   1.540 +   double p() const
   1.541 +   { return m_dist.p(); }
   1.542 +   void reset()
   1.543 +   { m_dist.reset(); }
   1.544 +   template<class UniformRandomNumberGenerator>
   1.545 +   result_type operator()(UniformRandomNumberGenerator& urng)
   1.546 +   {
   1.547 +      return m_dist(urng);
   1.548 +   }
   1.549 +#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
   1.550 +   template<class CharT, class Traits>
   1.551 +   friend std::basic_ostream<CharT,Traits>&
   1.552 +   operator<<(std::basic_ostream<CharT,Traits>& os,
   1.553 +            const bernoulli_distribution& lcg)
   1.554 +   {
   1.555 +      return os << lcg.m_dist;
   1.556 +   }
   1.557 +
   1.558 +   template<class CharT, class Traits>
   1.559 +   friend std::basic_istream<CharT,Traits>&
   1.560 +   operator>>(std::basic_istream<CharT,Traits>& is,
   1.561 +            bernoulli_distribution& lcg)
   1.562 +   {
   1.563 +      return is >> lcg.m_dist;
   1.564 +   }
   1.565 +#endif
   1.566 +
   1.567 +private:
   1.568 +   ::boost::bernoulli_distribution<double> m_dist;
   1.569 +};
   1.570 +//using ::boost::bernoulli_distribution;
   1.571 +using ::boost::geometric_distribution;
   1.572 +using ::boost::poisson_distribution;
   1.573 +using ::boost::binomial_distribution;
   1.574 +using ::boost::uniform_real;
   1.575 +using ::boost::exponential_distribution;
   1.576 +using ::boost::normal_distribution;
   1.577 +using ::boost::gamma_distribution;
   1.578 +
   1.579 +} }
   1.580 +
   1.581 +#endif
   1.582 +
   1.583 +#endif
   1.584 +