Microsimulation API
/home/marcle/src/R/microsimulation/src/rngstream-boost.hpp
Go to the documentation of this file.
1  /* boost random/rngstream-boost.hpp header file
2  *
3  * Copyright Mark Clements 2014
4  * Distributed under the Boost Software License, Version 1.0. (See
5  * accompanying file LICENSE_1_0.txt or copy at
6  * http://www.boost.org/LICENSE_1_0.txt)
7  *
8  * See http://www.boost.org for most recent version including documentation.
9  *
10  *
11  * Revision history
12  */
13 
14 /***********************************************************************\
15  *
16  * File: RngStream.cpp for multiple streams of Random Numbers
17  * Language: C++ (ISO 1998)
18  * Copyright: Pierre L'Ecuyer, University of Montreal
19  * Notice: This code can be used freely for personal, academic,
20  * or non-commercial purposes. For commercial purposes,
21  * please contact P. L'Ecuyer at: lecuyer@iro.umontreal.ca
22  * Date: 14 August 2001
23  *
24 \***********************************************************************/
25 
26 #ifndef BOOST_RANDOM_RNGSTREAM_BOOST_HPP
27 #define BOOST_RANDOM_RNGSTREAM_BOOST_HPP
28 
29 #include <iostream>
30 #include <stdexcept>
31 #include <boost/assert.hpp>
32 #include <boost/config.hpp>
33 #include <boost/cstdint.hpp>
34 #include <boost/limits.hpp>
35 #include <boost/static_assert.hpp>
36 #include <boost/integer/static_log2.hpp>
37 #include <boost/mpl/if.hpp>
38 #include <boost/type_traits/is_arithmetic.hpp>
39 #include <boost/random/detail/config.hpp>
40 #include <boost/random/detail/const_mod.hpp>
41 #include <boost/random/detail/seed.hpp>
42 //#include <boost/random/detail/seed_impl.hpp>
43 #include <boost/detail/workaround.hpp>
44 #include <string>
45 #include <cstdlib>
46 
47 #include <boost/random/detail/disable_warnings.hpp>
48 
49 #include <RngStream.h>
50 #include <RngStream.cpp>
51 
52 namespace boost {
53  namespace random {
54 
55  using ssim::RngStream;
56 
57  class rngstream : public RngStream
58  {
59  public:
60  typedef double result_type;
61 
62  //BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
66  static double min BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0.0; }
70  static double max BOOST_PREVENT_MACRO_SUBSTITUTION ()
71  { return 1.0; } // or 2^24?
72 
74  rngstream() : RngStream("") { }
75 
76  // compiler-generated copy ctor and assignment operator are fine
77 
79  void seed() {
80  unsigned long seed[6];
81  for (int i = 0; i<6; i++)
82  seed[i] = 12345ul;
83  SetSeed(seed);
84  }
85 
87  double operator()() { return RandU01(); }
88 
90  template<class Iter>
91  void generate(Iter first, Iter last)
92  {
93  for(; first != last; ++first) {
94  *first = (*this)();
95  }
96  }
97 
98 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
99 
100  template<class CharT,class Traits>
101  friend std::basic_ostream<CharT,Traits>&
102  operator<<(std::basic_ostream<CharT,Traits>& os, const rngstream& r)
103  {
104  unsigned long seed[6];
105  r.GetState (seed);
106  for (int i = 0; i<5; i++)
107  os << seed[i] << ' ';
108  os << seed[5];
109  return os;
110  }
111 
113  template<class CharT,class Traits>
114  friend std::basic_istream<CharT,Traits>&
115  operator>>(std::basic_istream<CharT,Traits>& is, rngstream& r)
116  {
117  unsigned long seed[6];
118  for (int i = 0; i<6; i++)
119  is >> seed[i];
120  r.SetSeed(seed);
121  return is;
122  }
123 #endif
124 
129  friend bool operator==(const rngstream& x, const rngstream& y)
130  {
131  unsigned long seedx[6], seedy[6];
132  x.GetState (seedx);
133  y.GetState (seedy);
134  for (int i = 0; i<6; i++)
135  if (seedx[i] != seedy[i])
136  return false;
137  return true;
138  }
143  friend bool operator!=(const rngstream& x, const rngstream& y)
144  { return !(x == y); }
145  };
146 
147  } // namespace random
148 
149  using random::rngstream;
150 
151 } // namespace boost
152 
153 #include <boost/random/detail/enable_warnings.hpp>
154 
155 #endif // BOOST_RANDOM_RNGSTREAM_BOOST_HPP
ssim::RngStream::GetState
void GetState(double seed[6]) const
Definition: RngStream.cpp:496
ssim::RngStream
Definition: RngStream.h:30
boost::random::rngstream::operator>>
friend std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &is, rngstream &r)
Definition: rngstream-boost.hpp:115
RngStream.cpp
ssim::RngStream::RandU01
double RandU01()
Definition: RngStream.cpp:566
boost
Definition: rngstream-boost.hpp:52
boost::random::rngstream::BOOST_PREVENT_MACRO_SUBSTITUTION
static double max BOOST_PREVENT_MACRO_SUBSTITUTION()
Definition: rngstream-boost.hpp:70
boost::random::rngstream::operator()
double operator()()
Definition: rngstream-boost.hpp:87
boost::random::rngstream::rngstream
rngstream()
Definition: rngstream-boost.hpp:74
boost::random::rngstream::operator==
friend bool operator==(const rngstream &x, const rngstream &y)
Definition: rngstream-boost.hpp:129
boost::random::rngstream::operator<<
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const rngstream &r)
Definition: rngstream-boost.hpp:102
boost::random::rngstream::seed
void seed()
Definition: rngstream-boost.hpp:79
ssim::RngStream::SetSeed
bool SetSeed(const double seed[6])
Definition: RngStream.cpp:402
boost::random::rngstream::operator!=
friend bool operator!=(const rngstream &x, const rngstream &y)
Definition: rngstream-boost.hpp:143
RngStream.h
boost::random::rngstream
Definition: rngstream-boost.hpp:57
boost::random::rngstream::generate
void generate(Iter first, Iter last)
Definition: rngstream-boost.hpp:91
boost::random::rngstream::result_type
double result_type
Definition: rngstream-boost.hpp:60
boost::random::rngstream::BOOST_PREVENT_MACRO_SUBSTITUTION
static double min BOOST_PREVENT_MACRO_SUBSTITUTION()
Definition: rngstream-boost.hpp:66