imgtools/imglib/boostlibrary/boost/tr1/random.hpp
author srilekhas <srilekhas@symbian.org>
Wed, 18 Aug 2010 11:18:38 +0100
changeset 627 cb3264f4c6e6
parent 600 6d08f4a05d93
permissions -rw-r--r--
Merge : re-applies missing part of fix for Bug 2901,Add export for s60ibymacros.pm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     1
//  (C) Copyright John Maddock 2005.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     2
//  (C) Copyright Henry S. Warren 2005.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     3
//  Use, modification and distribution are subject to the
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     4
//  Boost Software License, Version 1.0. (See accompanying file
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     5
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     6
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     7
#ifndef BOOST_TR1_RANDOM_HPP_INCLUDED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     8
#  define BOOST_TR1_RANDOM_HPP_INCLUDED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     9
#  include <boost/tr1/detail/config.hpp>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    10
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    11
#ifdef BOOST_HAS_TR1_RANDOM
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    12
#  ifdef BOOST_HAS_INCLUDE_NEXT
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    13
#     include_next BOOST_TR1_HEADER(random)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    14
#  else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
#     include <boost/tr1/detail/config_all.hpp>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
#     include BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(random))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
#  endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
#else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
// Boost.Random:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
#include <boost/random.hpp>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
#ifndef __SUNPRO_CC
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
    // Sunpros linker complains if we so much as include this...
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
#   include <boost/nondet_random.hpp>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
#include <boost/tr1/detail/functor2iterator.hpp>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
#include <boost/type_traits/is_fundamental.hpp>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
#include <boost/type_traits/is_same.hpp>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
namespace std { namespace tr1{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
using ::boost::variate_generator;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
template<class UIntType, UIntType a, UIntType c, UIntType m>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
class linear_congruential
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
private:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
   typedef ::boost::random::linear_congruential<UIntType, a, c, m, 0> impl_type;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
public:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
   // types
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
   typedef UIntType result_type;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
   // parameter values
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
   BOOST_STATIC_CONSTANT(UIntType, multiplier = a);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
   BOOST_STATIC_CONSTANT(UIntType, increment = c);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
   BOOST_STATIC_CONSTANT(UIntType, modulus = m);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
   // constructors and member function
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
   explicit linear_congruential(unsigned long x0 = 1)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
      : m_gen(x0){}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
   linear_congruential(const linear_congruential& that)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
      : m_gen(that.m_gen){}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
   template<class Gen> linear_congruential(Gen& g)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
      init1(g, ::boost::is_same<Gen,linear_congruential>());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
   void seed(unsigned long x0 = 1)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
   { m_gen.seed(x0); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
   template<class Gen> void seed(Gen& g)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
   { 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
      init2(g, ::boost::is_fundamental<Gen>());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
   { return (m_gen.min)(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
   { return (m_gen.max)(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
   result_type operator()()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
      return m_gen(); 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
   bool operator==(const linear_congruential& that)const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
   { return m_gen == that.m_gen; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
   bool operator!=(const linear_congruential& that)const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
   { return m_gen != that.m_gen; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
  template<class CharT, class Traits>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
  friend std::basic_ostream<CharT,Traits>&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
  operator<<(std::basic_ostream<CharT,Traits>& os,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
             const linear_congruential& lcg)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
  {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
    return os << lcg.m_gen; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
  }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
  template<class CharT, class Traits>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
  friend std::basic_istream<CharT,Traits>&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
  operator>>(std::basic_istream<CharT,Traits>& is,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
             linear_congruential& lcg)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
  {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
    return is >> lcg.m_gen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
  }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    91
private:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    92
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
   void init1(Gen& g, const ::boost::true_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
      m_gen = g.m_gen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
   void init1(Gen& g, const ::boost::false_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
      init2(g, ::boost::is_fundamental<Gen>());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
   void init2(Gen& g, const ::boost::true_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
      m_gen.seed(static_cast<unsigned long>(g));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
   void init2(Gen& g, const ::boost::false_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
      //typedef typename Gen::result_type gen_rt;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
      boost::tr1_details::functor2iterator<Gen, unsigned long> f1(g), f2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
      m_gen.seed(f1, f2);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
   impl_type m_gen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
};
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
template<class UIntType, int w, int n, int m, int r,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
UIntType a, int u, int s, UIntType b, int t, UIntType c, int l>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   119
class mersenne_twister
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   120
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   121
   typedef ::boost::random::mersenne_twister
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   122
      <UIntType, w, n, m, r, a, u, s, b, t, c, l, 0> imp_type;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   123
public:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   124
   // types
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   125
   typedef UIntType result_type;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   126
   // parameter values
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   127
   BOOST_STATIC_CONSTANT(int, word_size = w);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   128
   BOOST_STATIC_CONSTANT(int, state_size = n);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   129
   BOOST_STATIC_CONSTANT(int, shift_size = m);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   130
   BOOST_STATIC_CONSTANT(int, mask_bits = r);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   131
   BOOST_STATIC_CONSTANT(UIntType, parameter_a = a);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   132
   BOOST_STATIC_CONSTANT(int, output_u = u);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   133
   BOOST_STATIC_CONSTANT(int, output_s = s);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   134
   BOOST_STATIC_CONSTANT(UIntType, output_b = b);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   135
   BOOST_STATIC_CONSTANT(int, output_t = t);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   136
   BOOST_STATIC_CONSTANT(UIntType, output_c = c);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   137
   BOOST_STATIC_CONSTANT(int, output_l = l);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   138
   // constructors and member function
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   139
   mersenne_twister(){}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   140
   explicit mersenne_twister(unsigned long value)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   141
      : m_gen(value == 0 ? 5489UL : value){}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   142
   template<class Gen> mersenne_twister(Gen& g)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   143
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   144
      init1(g, ::boost::is_same<mersenne_twister,Gen>());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   145
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   146
   void seed()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   147
   { m_gen.seed(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   148
   void seed(unsigned long value)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   149
   { m_gen.seed(value == 0 ? 5489UL : value); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   150
   template<class Gen> void seed(Gen& g)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   151
   { init2(g, ::boost::is_fundamental<Gen>()); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   152
   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   153
   { return (m_gen.min)(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   154
   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   155
   { return (m_gen.max)(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   156
   result_type operator()()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   157
   { return m_gen(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   158
   bool operator==(const mersenne_twister& that)const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   159
   { return m_gen == that.m_gen; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   160
   bool operator!=(const mersenne_twister& that)const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   161
   { return m_gen != that.m_gen; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   162
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   163
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   164
   template<class CharT, class Traits>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   165
   friend std::basic_ostream<CharT,Traits>&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   166
   operator<<(std::basic_ostream<CharT,Traits>& os,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   167
            const mersenne_twister& lcg)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   168
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   169
      return os << lcg.m_gen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   170
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   171
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   172
   template<class CharT, class Traits>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   173
   friend std::basic_istream<CharT,Traits>&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   174
   operator>>(std::basic_istream<CharT,Traits>& is,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   175
            mersenne_twister& lcg)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   176
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   177
      return is >> lcg.m_gen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   178
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   179
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   180
private:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   181
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   182
   void init1(Gen& g, const ::boost::true_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   183
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   184
      m_gen = g.m_gen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   185
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   186
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   187
   void init1(Gen& g, const ::boost::false_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   188
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   189
      init2(g, ::boost::is_fundamental<Gen>());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   190
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   191
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   192
   void init2(Gen& g, const ::boost::true_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   193
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   194
      m_gen.seed(static_cast<unsigned long>(g == 0 ? 4357UL : g));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   195
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   196
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   197
   void init2(Gen& g, const ::boost::false_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   198
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   199
      m_gen.seed(g);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   200
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   201
   imp_type m_gen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   202
};
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   203
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   204
template<class IntType, IntType m, int s, int r>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   205
class subtract_with_carry
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   206
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   207
public:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   208
   // types
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   209
   typedef IntType result_type;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   210
   // parameter values
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   211
   BOOST_STATIC_CONSTANT(IntType, modulus = m);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   212
   BOOST_STATIC_CONSTANT(int, long_lag = r);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   213
   BOOST_STATIC_CONSTANT(int, short_lag = s);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   214
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   215
   // constructors and member function
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   216
   subtract_with_carry(){}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   217
   explicit subtract_with_carry(unsigned long value)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   218
      : m_gen(value == 0 ? 19780503UL : value){}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   219
   template<class Gen> subtract_with_carry(Gen& g)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   220
   { init1(g, ::boost::is_same<Gen, subtract_with_carry<IntType, m, s, r> >()); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   221
   void seed(unsigned long value = 19780503ul)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   222
   { m_gen.seed(value == 0 ? 19780503UL : value); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   223
   template<class Gen> void seed(Gen& g)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   224
   { init2(g, ::boost::is_fundamental<Gen>()); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   225
   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   226
   { return (m_gen.min)(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   227
   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   228
   { return (m_gen.max)(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   229
   result_type operator()()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   230
   { return m_gen(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   231
   bool operator==(const subtract_with_carry& that)const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   232
   { return m_gen == that.m_gen; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   233
   bool operator!=(const subtract_with_carry& that)const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   234
   { return m_gen != that.m_gen; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   235
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   236
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   237
   template<class CharT, class Traits>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   238
   friend std::basic_ostream<CharT,Traits>&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   239
   operator<<(std::basic_ostream<CharT,Traits>& os,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   240
            const subtract_with_carry& lcg)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   241
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   242
      return os << lcg.m_gen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   243
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   244
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   245
   template<class CharT, class Traits>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   246
   friend std::basic_istream<CharT,Traits>&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   247
   operator>>(std::basic_istream<CharT,Traits>& is,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   248
            subtract_with_carry& lcg)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   249
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   250
      return is >> lcg.m_gen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   251
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   252
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   253
private:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   254
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   255
   void init1(Gen& g, const ::boost::true_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   256
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   257
      m_gen = g.m_gen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   258
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   259
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   260
   void init1(Gen& g, const ::boost::false_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   261
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   262
      init2(g, ::boost::is_fundamental<Gen>());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   263
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   264
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   265
   void init2(Gen& g, const ::boost::true_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   266
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   267
      m_gen.seed(static_cast<unsigned long>(g == 0 ? 19780503UL : g));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   268
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   269
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   270
   void init2(Gen& g, const ::boost::false_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   271
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   272
      m_gen.seed(g);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   273
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   274
   ::boost::random::subtract_with_carry<IntType, m, s, r, 0> m_gen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   275
};
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   276
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   277
template<class RealType, int w, int s, int r>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   278
class subtract_with_carry_01
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   279
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   280
public:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   281
   // types
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   282
   typedef RealType result_type;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   283
   // parameter values
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   284
   BOOST_STATIC_CONSTANT(int, word_size = w);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   285
   BOOST_STATIC_CONSTANT(int, long_lag = r);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   286
   BOOST_STATIC_CONSTANT(int, short_lag = s);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   287
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   288
   // constructors and member function
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   289
   subtract_with_carry_01(){}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   290
   explicit subtract_with_carry_01(unsigned long value)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   291
      : m_gen(value == 0 ? 19780503UL : value){}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   292
   template<class Gen> subtract_with_carry_01(Gen& g)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   293
   { init1(g, ::boost::is_same<Gen, subtract_with_carry_01<RealType, w, s, r> >()); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   294
   void seed(unsigned long value = 19780503UL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   295
   { m_gen.seed(value == 0 ? 19780503UL : value); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   296
   template<class Gen> void seed(Gen& g)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   297
   { init2(g, ::boost::is_fundamental<Gen>()); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   298
   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   299
   { return (m_gen.min)(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   300
   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   301
   { return (m_gen.max)(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   302
   result_type operator()()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   303
   { return m_gen(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   304
   bool operator==(const subtract_with_carry_01& that)const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   305
   { return m_gen == that.m_gen; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   306
   bool operator!=(const subtract_with_carry_01& that)const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   307
   { return m_gen != that.m_gen; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   308
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   309
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   310
   template<class CharT, class Traits>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   311
   friend std::basic_ostream<CharT,Traits>&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   312
   operator<<(std::basic_ostream<CharT,Traits>& os,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   313
            const subtract_with_carry_01& lcg)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   314
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   315
      return os << lcg.m_gen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   316
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   317
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   318
   template<class CharT, class Traits>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   319
   friend std::basic_istream<CharT,Traits>&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   320
   operator>>(std::basic_istream<CharT,Traits>& is,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   321
            subtract_with_carry_01& lcg)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   322
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   323
      return is >> lcg.m_gen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   324
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   325
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   326
private:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   327
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   328
   void init1(Gen& g, const ::boost::true_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   329
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   330
      m_gen = g.m_gen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   331
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   332
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   333
   void init1(Gen& g, const ::boost::false_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   334
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   335
      init2(g, ::boost::is_fundamental<Gen>());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   336
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   337
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   338
   void init2(Gen& g, const ::boost::true_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   339
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   340
      m_gen.seed(static_cast<unsigned long>(g == 0 ? 19780503UL : g));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   341
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   342
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   343
   void init2(Gen& g, const ::boost::false_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   344
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   345
      //typedef typename Gen::result_type gen_rt;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   346
      boost::tr1_details::functor2iterator<Gen, unsigned long> f1(g), f2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   347
      m_gen.seed(f1, f2);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   348
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   349
   ::boost::random::subtract_with_carry_01<RealType, w, s, r, 0> m_gen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   350
};
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   351
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   352
using ::boost::random::discard_block;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   353
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   354
template<class UniformRandomNumberGenerator1, int s1, class UniformRandomNumberGenerator2, int s2>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   355
class xor_combine
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   356
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   357
public:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   358
   // types
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   359
   typedef UniformRandomNumberGenerator1 base1_type;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   360
   typedef UniformRandomNumberGenerator2 base2_type;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   361
   typedef unsigned long result_type;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   362
   // parameter values
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   363
   BOOST_STATIC_CONSTANT(int, shift1 = s1);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   364
   BOOST_STATIC_CONSTANT(int, shift2 = s2);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   365
   // constructors and member function
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   366
   xor_combine(){ init_minmax(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   367
   xor_combine(const base1_type & rng1, const base2_type & rng2)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   368
      : m_b1(rng1), m_b2(rng2) { init_minmax(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   369
   xor_combine(unsigned long s)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   370
      : m_b1(s), m_b2(s+1) { init_minmax(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   371
   template<class Gen> xor_combine(Gen& g)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   372
   { 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   373
      init_minmax(); 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   374
      init1(g, ::boost::is_same<Gen, xor_combine<UniformRandomNumberGenerator1, s1, UniformRandomNumberGenerator2, s2> >());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   375
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   376
   void seed()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   377
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   378
      m_b1.seed();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   379
      m_b2.seed();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   380
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   381
   void seed(unsigned long s)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   382
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   383
      m_b1.seed(s);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   384
      m_b2.seed(s+1);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   385
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   386
   template<class Gen> void seed(Gen& g)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   387
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   388
      init2(g, ::boost::is_fundamental<Gen>());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   389
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   390
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   391
   const base1_type& base1() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   392
   { return m_b1; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   393
   const base2_type& base2() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   394
   { return m_b2; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   395
   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   396
   { return m_min; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   397
   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   398
   { return m_max; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   399
   result_type operator()()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   400
   { return (m_b1() << s1) ^ (m_b2() << s2); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   401
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   402
   bool operator == (const xor_combine& that)const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   403
   { return (m_b1 == that.m_b1) && (m_b2 == that.m_b2); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   404
   bool operator != (const xor_combine& that)const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   405
   { return !(*this == that); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   406
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   407
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   408
   template<class CharT, class Traits>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   409
   friend std::basic_ostream<CharT,Traits>&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   410
   operator<<(std::basic_ostream<CharT,Traits>& os,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   411
            const xor_combine& lcg)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   412
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   413
      return os << lcg.m_b1 << " " << lcg.m_b2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   414
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   415
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   416
   template<class CharT, class Traits>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   417
   friend std::basic_istream<CharT,Traits>&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   418
   operator>>(std::basic_istream<CharT,Traits>& is,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   419
            xor_combine& lcg)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   420
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   421
      return is >> lcg.m_b1 >> lcg.m_b2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   422
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   423
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   424
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   425
private:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   426
   void init_minmax();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   427
   base1_type m_b1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   428
   base2_type m_b2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   429
   result_type m_min;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   430
   result_type m_max;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   431
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   432
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   433
   void init1(Gen& g, const ::boost::true_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   434
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   435
      m_b1 = g.m_b1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   436
      m_b2 = g.m_b2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   437
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   438
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   439
   void init1(Gen& g, const ::boost::false_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   440
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   441
      init2(g, ::boost::is_fundamental<Gen>());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   442
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   443
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   444
   void init2(Gen& g, const ::boost::true_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   445
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   446
      m_b1.seed(static_cast<unsigned long>(g));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   447
      m_b2.seed(static_cast<unsigned long>(g));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   448
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   449
   template <class Gen>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   450
   void init2(Gen& g, const ::boost::false_type&)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   451
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   452
      m_b1.seed(g);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   453
      m_b2.seed(g);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   454
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   455
};
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   456
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   457
template<class UniformRandomNumberGenerator1, int s1, class UniformRandomNumberGenerator2, int s2>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   458
void xor_combine<UniformRandomNumberGenerator1, s1, UniformRandomNumberGenerator2, s2>::init_minmax()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   459
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   460
   //
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   461
   // The following code is based on that given in "Hacker's Delight"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   462
   // by Henry S. Warren, (Addison-Wesley, 2003), and at 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   463
   // http://www.hackersdelight.org/index.htm.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   464
   // Used here by permission.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   465
   //
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   466
   // calculation of minimum value:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   467
   //
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   468
   result_type a = (m_b1.min)() << s1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   469
   result_type b = (m_b1.max)() << s1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   470
   result_type c = (m_b2.min)() << s2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   471
   result_type d = (m_b2.max)() << s2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   472
   result_type m, temp;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   473
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   474
   m = 0x1uL << ((sizeof(result_type) * CHAR_BIT) - 1);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   475
   while (m != 0) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   476
      if (~a & c & m) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   477
         temp = (a | m) & (static_cast<result_type>(0u) - m);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   478
         if (temp <= b) a = temp;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   479
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   480
      else if (a & ~c & m) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   481
         temp = (c | m) & (static_cast<result_type>(0u) - m);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   482
         if (temp <= d) c = temp;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   483
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   484
      m >>= 1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   485
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   486
   m_min = a ^ c;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   487
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   488
   //
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   489
   // calculation of maximum value:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   490
   //
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   491
   if((((std::numeric_limits<result_type>::max)() >> s1) < (m_b1.max)())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   492
      || ((((std::numeric_limits<result_type>::max)()) >> s2) < (m_b2.max)()))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   493
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   494
      m_max = (std::numeric_limits<result_type>::max)();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   495
      return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   496
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   497
   a = (m_b1.min)() << s1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   498
   b = (m_b1.max)() << s1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   499
   c = (m_b2.min)() << s2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   500
   d = (m_b2.max)() << s2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   501
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   502
   m = 0x1uL << ((sizeof(result_type) * CHAR_BIT) - 1);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   503
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   504
   while (m != 0) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   505
      if (b & d & m) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   506
         temp = (b - m) | (m - 1);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   507
         if (temp >= a) b = temp;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   508
         else {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   509
            temp = (d - m) | (m - 1);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   510
            if (temp >= c) d = temp;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   511
         }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   512
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   513
      m = m >> 1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   514
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   515
   m_max = b ^ d;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   516
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   517
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   518
typedef linear_congruential< ::boost::int32_t, 16807, 0, 2147483647> minstd_rand0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   519
typedef linear_congruential< ::boost::int32_t, 48271, 0, 2147483647> minstd_rand;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   520
typedef mersenne_twister< ::boost::uint32_t, 32,624,397,31,0x9908b0df,11,7,0x9d2c5680,15,0xefc60000,18> mt19937;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   521
typedef subtract_with_carry_01<float, 24, 10, 24> ranlux_base_01;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   522
typedef subtract_with_carry_01<double, 48, 10, 24> ranlux64_base_01;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   523
typedef discard_block<subtract_with_carry< ::boost::int32_t, (1<<24), 10, 24>, 223, 24> ranlux3;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   524
typedef discard_block<subtract_with_carry< ::boost::int32_t, (1<<24), 10, 24>, 389, 24> ranlux4;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   525
typedef discard_block<subtract_with_carry_01<float, 24, 10, 24>, 223, 24> ranlux3_01;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   526
typedef discard_block<subtract_with_carry_01<float, 24, 10, 24>, 389, 24> ranlux4_01;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   527
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   528
#ifndef __SUNPRO_CC
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   529
using ::boost::random_device;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   530
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   531
using ::boost::uniform_int;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   532
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   533
class bernoulli_distribution
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   534
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   535
public:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   536
   // types
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   537
   typedef int input_type;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   538
   typedef bool result_type;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   539
   // constructors and member function
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   540
   explicit bernoulli_distribution(double p = 0.5)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   541
      : m_dist(p){}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   542
   double p() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   543
   { return m_dist.p(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   544
   void reset()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   545
   { m_dist.reset(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   546
   template<class UniformRandomNumberGenerator>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   547
   result_type operator()(UniformRandomNumberGenerator& urng)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   548
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   549
      return m_dist(urng);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   550
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   551
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   552
   template<class CharT, class Traits>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   553
   friend std::basic_ostream<CharT,Traits>&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   554
   operator<<(std::basic_ostream<CharT,Traits>& os,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   555
            const bernoulli_distribution& lcg)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   556
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   557
      return os << lcg.m_dist;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   558
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   559
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   560
   template<class CharT, class Traits>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   561
   friend std::basic_istream<CharT,Traits>&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   562
   operator>>(std::basic_istream<CharT,Traits>& is,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   563
            bernoulli_distribution& lcg)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   564
   {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   565
      return is >> lcg.m_dist;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   566
   }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   567
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   568
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   569
private:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   570
   ::boost::bernoulli_distribution<double> m_dist;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   571
};
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   572
//using ::boost::bernoulli_distribution;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   573
using ::boost::geometric_distribution;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   574
using ::boost::poisson_distribution;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   575
using ::boost::binomial_distribution;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   576
using ::boost::uniform_real;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   577
using ::boost::exponential_distribution;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   578
using ::boost::normal_distribution;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   579
using ::boost::gamma_distribution;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   580
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   581
} }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   582
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   583
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   584
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   585
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   586