COPASI API  4.16.103
Public Member Functions | Protected Member Functions | Private Attributes | Friends | List of all members
Cmt19937 Class Reference

#include <Cmt19937.h>

Inheritance diagram for Cmt19937:
Inheritance graph
[legend]
Collaboration diagram for Cmt19937:
Collaboration graph
[legend]

Public Member Functions

C_FLOAT64 genrand_res53 ()
 
C_FLOAT64 getRandomCC ()
 
C_FLOAT64 getRandomCO ()
 
C_FLOAT64 getRandomOO ()
 
C_INT32 getRandomS ()
 
unsigned C_INT32 getRandomU ()
 
void init_by_array (unsigned C_INT32 init_key[], C_INT32 key_length)
 
void initialize (unsigned C_INT32 seed=CRandom::getSystemSeed())
 
 ~Cmt19937 ()
 
- Public Member Functions inherited from CRandom
const unsigned C_INT32getModulus () const
 
virtual C_FLOAT64 getRandomExp ()
 
virtual C_FLOAT64 getRandomGamma (C_FLOAT64 shape, C_FLOAT64 scale)
 
virtual C_FLOAT64 getRandomNormal (const C_FLOAT64 &mean, const C_FLOAT64 &sd)
 
virtual C_FLOAT64 getRandomNormal01 ()
 
virtual C_FLOAT64 getRandomNormalLog (const C_FLOAT64 &mean, const C_FLOAT64 &sd)
 
virtual C_FLOAT64 getRandomNormalPositive (const C_FLOAT64 &mean, const C_FLOAT64 &sd)
 
virtual C_FLOAT64 getRandomPoisson (const C_FLOAT64 &mean)
 
virtual C_INT32 getRandomS (const C_INT32 &max)
 
virtual C_FLOAT64 getRandomStdGamma (C_FLOAT64 shape)
 
virtual unsigned C_INT32 getRandomU (const unsigned C_INT32 &max)
 
const CRandom::TypegetType () const
 
virtual ~CRandom ()
 

Protected Member Functions

 Cmt19937 (unsigned C_INT32 seed)
 
void next_state ()
 
- Protected Member Functions inherited from CRandom
 CRandom ()
 
void setModulus (const unsigned C_INT32 &modulus)
 

Private Attributes

C_INT mLeft
 
unsigned C_INT32mNext
 
unsigned C_INT32 mState [624]
 

Friends

CRandomCRandom::createGenerator (CRandom::Type type, unsigned C_INT32 seed)
 

Additional Inherited Members

- Public Types inherited from CRandom
enum  Type { r250 = 0, mt19937, mt19937HR, unkown }
 
- Static Public Member Functions inherited from CRandom
static CRandomcreateGenerator (CRandom::Type type=CRandom::mt19937, unsigned C_INT32 seed=0)
 
static unsigned C_INT32 getSystemSeed ()
 
- Static Public Attributes inherited from CRandom
static const std::string TypeName []
 
static const char * XMLType []
 
- Protected Attributes inherited from CRandom
C_FLOAT64 mFloat
 
unsigned C_INT32 mModulus
 
C_FLOAT64 mModulusInv
 
C_FLOAT64 mModulusInv1
 
C_INT32 mNumberS
 
unsigned C_INT32 mNumberU
 
CRandom::Type mType
 

Detailed Description

Definition at line 67 of file Cmt19937.h.

Constructor & Destructor Documentation

Cmt19937::Cmt19937 ( unsigned C_INT32  seed)
protected

Default/Named constructor. Seeds the random number generator with the given seed.

Parameters
C_INT32seed

Definition at line 75 of file Cmt19937.cpp.

References initialize(), and CRandom::setModulus().

75  :
76  CRandom(),
77  mLeft(1),
78  mNext(NULL)
79 {
80  setModulus(0xffffffffUL);
81  initialize(seed);
82 }
void initialize(unsigned C_INT32 seed=CRandom::getSystemSeed())
Definition: Cmt19937.cpp:87
void setModulus(const unsigned C_INT32 &modulus)
Definition: CRandom.cpp:129
CRandom()
Definition: CRandom.cpp:83
unsigned C_INT32 * mNext
Definition: Cmt19937.h:78
C_INT mLeft
Definition: Cmt19937.h:76
Cmt19937::~Cmt19937 ( )

The destructor.

Definition at line 84 of file Cmt19937.cpp.

84 {}

Member Function Documentation

C_FLOAT64 Cmt19937::genrand_res53 ( )

Definition at line 241 of file Cmt19937.cpp.

References C_INT32, getRandomU(), and CRandom::mFloat.

242 {
243  unsigned C_INT32 a = getRandomU() >> 5, b = getRandomU() >> 6;
244  return mFloat = (a * 67108864.0 + b) * (1.0 / 9007199254740992.0);
245 }
C_FLOAT64 mFloat
Definition: CRandom.h:88
#define C_INT32
Definition: copasi.h:90
unsigned C_INT32 getRandomU()
Definition: Cmt19937.cpp:158
C_FLOAT64 Cmt19937::getRandomCC ( )
virtual

Produces a uniformly distributed random number in 0 <= x <= 1.

Returns
C_FLOAT64 random

Reimplemented from CRandom.

Reimplemented in Cmt19937HR.

Definition at line 190 of file Cmt19937.cpp.

References C_FLOAT64, mLeft, mNext, CRandom::mNumberU, and next_state().

191 {
192  if (--mLeft == 0)
193  next_state();
194  mNumberU = *mNext++;
195 
196  /* Tempering */
197  mNumberU ^= (mNumberU >> 11);
198  mNumberU ^= (mNumberU << 7) & 0x9d2c5680UL;
199  mNumberU ^= (mNumberU << 15) & 0xefc60000UL;
200  mNumberU ^= (mNumberU >> 18);
201 
202  return ((C_FLOAT64) mNumberU) * (1.0 / 4294967295.0);
203  /* divided by 2^32-1 */
204 }
void next_state()
Definition: Cmt19937.cpp:140
#define C_FLOAT64
Definition: copasi.h:92
unsigned C_INT32 * mNext
Definition: Cmt19937.h:78
C_INT mLeft
Definition: Cmt19937.h:76
unsigned C_INT32 mNumberU
Definition: CRandom.h:78
C_FLOAT64 Cmt19937::getRandomCO ( )
virtual

Produces a uniformly distributed random number in 0 <= x < 1. Note: 0 < x <= 1 may be achieved by 1.0 - getRandomCO().

Returns
C_FLOAT64 random

Reimplemented from CRandom.

Reimplemented in Cmt19937HR.

Definition at line 207 of file Cmt19937.cpp.

References C_FLOAT64, mLeft, mNext, CRandom::mNumberU, and next_state().

208 {
209  if (--mLeft == 0)
210  next_state();
211  mNumberU = *mNext++;
212 
213  /* Tempering */
214  mNumberU ^= (mNumberU >> 11);
215  mNumberU ^= (mNumberU << 7) & 0x9d2c5680UL;
216  mNumberU ^= (mNumberU << 15) & 0xefc60000UL;
217  mNumberU ^= (mNumberU >> 18);
218 
219  return ((C_FLOAT64) mNumberU) * (1.0 / 4294967296.0);
220  /* divided by 2^32 */
221 }
void next_state()
Definition: Cmt19937.cpp:140
#define C_FLOAT64
Definition: copasi.h:92
unsigned C_INT32 * mNext
Definition: Cmt19937.h:78
C_INT mLeft
Definition: Cmt19937.h:76
unsigned C_INT32 mNumberU
Definition: CRandom.h:78
C_FLOAT64 Cmt19937::getRandomOO ( )
virtual

Produces a uniformly distributed random number in 0 < x < 1.

Returns
C_FLOAT64 random

Reimplemented from CRandom.

Reimplemented in Cmt19937HR.

Definition at line 224 of file Cmt19937.cpp.

References C_FLOAT64, mLeft, mNext, CRandom::mNumberU, and next_state().

225 {
226  if (--mLeft == 0)
227  next_state();
228  mNumberU = *mNext++;
229 
230  /* Tempering */
231  mNumberU ^= (mNumberU >> 11);
232  mNumberU ^= (mNumberU << 7) & 0x9d2c5680UL;
233  mNumberU ^= (mNumberU << 15) & 0xefc60000UL;
234  mNumberU ^= (mNumberU >> 18);
235 
236  return (((C_FLOAT64) mNumberU) + 0.5) * (1.0 / 4294967296.0);
237  /* divided by 2^32 */
238 }
void next_state()
Definition: Cmt19937.cpp:140
#define C_FLOAT64
Definition: copasi.h:92
unsigned C_INT32 * mNext
Definition: Cmt19937.h:78
C_INT mLeft
Definition: Cmt19937.h:76
unsigned C_INT32 mNumberU
Definition: CRandom.h:78
C_INT32 Cmt19937::getRandomS ( )
virtual

Get a random number in 0 <= n <= (Modulus & 0x7ffffff)

Returns
C_INT32 random

Reimplemented from CRandom.

Definition at line 174 of file Cmt19937.cpp.

References mLeft, mNext, CRandom::mNumberU, and next_state().

175 {
176  if (--mLeft == 0)
177  next_state();
178  mNumberU = *mNext++;
179 
180  /* Tempering */
181  mNumberU ^= (mNumberU >> 11);
182  mNumberU ^= (mNumberU << 7) & 0x9d2c5680UL;
183  mNumberU ^= (mNumberU << 15) & 0xefc60000UL;
184  mNumberU ^= (mNumberU >> 18);
185 
186  return mNumberU >> 1;
187 }
void next_state()
Definition: Cmt19937.cpp:140
unsigned C_INT32 * mNext
Definition: Cmt19937.h:78
C_INT mLeft
Definition: Cmt19937.h:76
unsigned C_INT32 mNumberU
Definition: CRandom.h:78
unsigned C_INT32 Cmt19937::getRandomU ( )
virtual

Get a random number in 0 <= n <= Modulus

Returns
unsigned C_INT32 random

Reimplemented from CRandom.

Definition at line 158 of file Cmt19937.cpp.

References mLeft, mNext, CRandom::mNumberU, and next_state().

Referenced by genrand_res53(), Cmt19937HR::getRandomCC(), Cmt19937HR::getRandomCO(), and Cmt19937HR::getRandomOO().

159 {
160  if (--mLeft == 0)
161  next_state();
162  mNumberU = *mNext++;
163 
164  /* Tempering */
165  mNumberU ^= (mNumberU >> 11);
166  mNumberU ^= (mNumberU << 7) & 0x9d2c5680UL;
167  mNumberU ^= (mNumberU << 15) & 0xefc60000UL;
168  mNumberU ^= (mNumberU >> 18);
169 
170  return mNumberU;
171 }
void next_state()
Definition: Cmt19937.cpp:140
unsigned C_INT32 * mNext
Definition: Cmt19937.h:78
C_INT mLeft
Definition: Cmt19937.h:76
unsigned C_INT32 mNumberU
Definition: CRandom.h:78
void Cmt19937::init_by_array ( unsigned C_INT32  init_key[],
C_INT32  key_length 
)

Definition at line 106 of file Cmt19937.cpp.

References Cmt19937_N, initialize(), mLeft, and mState.

108 {
109  int i, j, k;
110  initialize(19650218UL);
111  i = 1;
112  j = 0;
113  k = (Cmt19937_N > key_length ? Cmt19937_N : key_length);
114  for (; k; k--)
115  {
116  mState[i] = (mState[i] ^ ((mState[i - 1] ^ (mState[i - 1] >> 30)) * 1664525UL))
117  + init_key[j] + j; /* non linear */
118  mState[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
119  i++;
120  j++;
121  if (i >= Cmt19937_N)
122  {mState[0] = mState[Cmt19937_N - 1]; i = 1;}
123  if (j >= key_length)
124  j = 0;
125  }
126  for (k = Cmt19937_N - 1; k; k--)
127  {
128  mState[i] = (mState[i] ^ ((mState[i - 1] ^ (mState[i - 1] >> 30)) * 1566083941UL))
129  - i; /* non linear */
130  mState[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
131  i++;
132  if (i >= Cmt19937_N)
133  {mState[0] = mState[Cmt19937_N - 1]; i = 1;}
134  }
135 
136  mState[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
137  mLeft = 1;
138 }
void initialize(unsigned C_INT32 seed=CRandom::getSystemSeed())
Definition: Cmt19937.cpp:87
unsigned C_INT32 mState[624]
Definition: Cmt19937.h:74
#define Cmt19937_N
Definition: Cmt19937.h:65
C_INT mLeft
Definition: Cmt19937.h:76
void Cmt19937::initialize ( unsigned C_INT32  seed = CRandom::getSystemSeed())
virtual

Initialize or reinitialize the random number generator with the given seed.

Parameters
unsignedC_INT32 seed (default system seed)

Reimplemented from CRandom.

Definition at line 87 of file Cmt19937.cpp.

References Cmt19937_N, mLeft, and mState.

Referenced by Cmt19937(), and init_by_array().

88 {
89  int j;
90  mState[0] = seed & 0xffffffffUL;
91  for (j = 1; j < Cmt19937_N; j++)
92  {
93  mState[j] = (1812433253UL * (mState[j - 1] ^ (mState[j - 1] >> 30)) + j);
94  /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
95  /* In the previous versions, MSBs of the seed affect */
96  /* only MSBs of the array mState[]. */
97  /* 2002/01/09 modified by Makoto Matsumoto */
98  mState[j] &= 0xffffffffUL; /* for >32 bit machines */
99  }
100  mLeft = 1;
101 }
unsigned C_INT32 mState[624]
Definition: Cmt19937.h:74
#define Cmt19937_N
Definition: Cmt19937.h:65
C_INT mLeft
Definition: Cmt19937.h:76
void Cmt19937::next_state ( )
protected

Definition at line 140 of file Cmt19937.cpp.

References C_INT32, Cmt19937_M, Cmt19937_N, Cmt19937_TWIST, mLeft, mNext, and mState.

Referenced by getRandomCC(), getRandomCO(), getRandomOO(), getRandomS(), and getRandomU().

141 {
142  unsigned C_INT32 *p = mState;
143  int j;
144 
145  mLeft = Cmt19937_N;
146  mNext = mState;
147 
148  for (j = Cmt19937_N - Cmt19937_M + 1; --j; p++)
149  *p = p[Cmt19937_M] ^ Cmt19937_TWIST(p[0], p[1]);
150 
151  for (j = Cmt19937_M; --j; p++)
152  *p = p[Cmt19937_M - Cmt19937_N] ^ Cmt19937_TWIST(p[0], p[1]);
153 
154  *p = p[Cmt19937_M - Cmt19937_N] ^ Cmt19937_TWIST(p[0], mState[0]);
155 }
unsigned C_INT32 mState[624]
Definition: Cmt19937.h:74
#define C_INT32
Definition: copasi.h:90
#define Cmt19937_TWIST(u, v)
Definition: Cmt19937.cpp:72
unsigned C_INT32 * mNext
Definition: Cmt19937.h:78
#define Cmt19937_N
Definition: Cmt19937.h:65
C_INT mLeft
Definition: Cmt19937.h:76
#define Cmt19937_M
Definition: Cmt19937.cpp:66

Friends And Related Function Documentation

CRandom* CRandom::createGenerator ( CRandom::Type  type,
unsigned C_INT32  seed 
)
friend

Member Data Documentation

C_INT Cmt19937::mLeft
private
unsigned C_INT32* Cmt19937::mNext
private

Definition at line 78 of file Cmt19937.h.

Referenced by getRandomCC(), getRandomCO(), getRandomOO(), getRandomS(), getRandomU(), and next_state().

unsigned C_INT32 Cmt19937::mState[624]
private

Definition at line 74 of file Cmt19937.h.

Referenced by init_by_array(), initialize(), and next_state().


The documentation for this class was generated from the following files: