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

#include <Cr250.h>

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

Public Member Functions

C_FLOAT64 getRandomCC ()
 
C_FLOAT64 getRandomCO ()
 
C_FLOAT64 getRandomOO ()
 
C_INT32 getRandomS ()
 
unsigned C_INT32 getRandomU ()
 
void initialize (unsigned C_INT32 seed=CRandom::getSystemSeed())
 
 ~Cr250 ()
 
- 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 ()
 

Private Member Functions

 Cr250 (unsigned C_INT32 seed)
 
C_FLOAT64 dr250 (void)
 
unsigned C_INT16 myrand ()
 
unsigned C_INT32 r250 (void)
 
unsigned C_INT32 r250n (const unsigned C_INT16 &max)
 

Private Attributes

unsigned C_INT16 mBuffer [250]
 
C_INT32 mIndex
 
unsigned C_INT32 mSeed
 

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 Member Functions inherited from CRandom
 CRandom ()
 
void setModulus (const unsigned C_INT32 &modulus)
 
- 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

Cr250 class implementing the R250 random number generator, by W. L. Maier

Created for Copasi by Stefan Hoops (C) Stefan Hoops 2002

Definition at line 23 of file Cr250.h.

Constructor & Destructor Documentation

Cr250::Cr250 ( unsigned C_INT32  seed)
private

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

Parameters
C_INT32seed

Definition at line 54 of file Cr250.cpp.

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

54  :
55  CRandom(),
56  mIndex(0)
57 {
58  setModulus(65535);
59  initialize(seed);
60 }
void initialize(unsigned C_INT32 seed=CRandom::getSystemSeed())
Definition: Cr250.cpp:63
void setModulus(const unsigned C_INT32 &modulus)
Definition: CRandom.cpp:129
CRandom()
Definition: CRandom.cpp:83
C_INT32 mIndex
Definition: Cr250.h:30
Cr250::~Cr250 ( )

The destructor.

Definition at line 61 of file Cr250.cpp.

61 {}

Member Function Documentation

C_FLOAT64 Cr250::dr250 ( void  )
private

Number returned by dr250() is in range [0,1)

Returns
C_FLOAT64 random

Definition at line 147 of file Cr250.cpp.

References CRandom::mNumberU, and r250().

Referenced by getRandomCO().

148 {
149  mNumberU = r250();
150  return mNumberU / 65536.; /* Return a number in [0.0 to 1.0) */
151 }
unsigned C_INT32 r250(void)
Definition: Cr250.cpp:112
unsigned C_INT32 mNumberU
Definition: CRandom.h:78
C_FLOAT64 Cr250::getRandomCC ( )
virtual

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

Returns
C_FLOAT64 random

Reimplemented from CRandom.

Definition at line 103 of file Cr250.cpp.

References CRandom::mModulusInv, and r250().

104 {return r250() * mModulusInv;}
unsigned C_INT32 r250(void)
Definition: Cr250.cpp:112
C_FLOAT64 mModulusInv
Definition: CRandom.h:103
C_FLOAT64 Cr250::getRandomCO ( )
virtual

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

Returns
const C_FLOAT64 & random

Reimplemented from CRandom.

Definition at line 106 of file Cr250.cpp.

References dr250().

107 {return dr250();}
C_FLOAT64 dr250(void)
Definition: Cr250.cpp:147
C_FLOAT64 Cr250::getRandomOO ( )
virtual

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

Returns
const C_FLOAT64 & random

Reimplemented from CRandom.

Definition at line 109 of file Cr250.cpp.

References CRandom::mModulusInv1, and r250().

110 {return (r250() + .5) * mModulusInv1;}
unsigned C_INT32 r250(void)
Definition: Cr250.cpp:112
C_FLOAT64 mModulusInv1
Definition: CRandom.h:108
C_INT32 Cr250::getRandomS ( )
virtual

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

Returns
C_INT32 random

Reimplemented from CRandom.

Definition at line 100 of file Cr250.cpp.

References r250().

101 {return r250();}
unsigned C_INT32 r250(void)
Definition: Cr250.cpp:112
unsigned C_INT32 Cr250::getRandomU ( )
virtual

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

Returns
unsigned C_INT32 random

Reimplemented from CRandom.

Definition at line 97 of file Cr250.cpp.

References r250().

98 {return r250();}
unsigned C_INT32 r250(void)
Definition: Cr250.cpp:112
void Cr250::initialize ( unsigned C_INT32  seed = CRandom::getSystemSeed())
virtual

Initialize or reinitialize the random number generator with the given seed. Note: seed = 12345 gives the default initilization as in W. L. Maier code

Parameters
unsignedC_INT32 seed (default system seed)

Reimplemented from CRandom.

Definition at line 63 of file Cr250.cpp.

References mBuffer, mIndex, mSeed, and myrand().

Referenced by Cr250().

64 {
65  /*--------------------------------------------------------------------------*/
66  int j, k;
67  unsigned int mask;
68  unsigned int msb;
69  /*--------------------------------------------------------------------------*/
70 
71  mIndex = 0;
72  mSeed = seed;
73 
74  /* Fill the r250 buffer with 15-bit values */
75  for (j = 0; j < 250; j++)
76  mBuffer[j] = myrand();
77 
78  /* Set some of the MS bits to 1 */
79  for (j = 0; j < 250; j++)
80  if (myrand() > 16384)
81  mBuffer[j] |= 0x8000;
82 
83  msb = 0x8000; /* To turn on the diagonal bit */
84  mask = 0xffff; /* To turn off the leftmost bits */
85 
86  for (j = 0; j < 16; j++)
87  {
88  k = 11 * j + 3; /* Select a word to operate on */
89  mBuffer[k] &= mask; /* Turn off bits left of the diagonal */
90  mBuffer[k] |= msb; /* Turn on the diagonal bit */
91  mask >>= 1;
92  msb >>= 1;
93  }
94  return;
95 }
unsigned C_INT32 mSeed
Definition: Cr250.h:32
C_INT32 mIndex
Definition: Cr250.h:30
unsigned C_INT16 mBuffer[250]
Definition: Cr250.h:34
unsigned C_INT16 myrand()
Definition: Cr250.cpp:153
unsigned C_INT16 Cr250::myrand ( )
private

Linear congruent pseudorandom number generator for initialization. Return a pseudorandom number in the interval 0 <= n <= 32767.

Definition at line 153 of file Cr250.cpp.

References mSeed.

Referenced by initialize().

154 {
155  mSeed = mSeed * 0x015a4e35L + 1;
156  return (mSeed >> 16)&0x7fff;
157 }
unsigned C_INT32 mSeed
Definition: Cr250.h:32
unsigned C_INT32 Cr250::r250 ( void  )
private

Number returned by r250() is in the interval 0 <= k <= 65535.

Returns
unsigned C_INT32 random

Definition at line 112 of file Cr250.cpp.

References C_INT16, mBuffer, mIndex, and CRandom::mNumberU.

Referenced by dr250(), getRandomCC(), getRandomOO(), getRandomS(), getRandomU(), and r250n().

113 {
114  register C_INT16 j;
115 
116  if (mIndex > 146)
117  j = mIndex - 147; /* Wrap pointer around */
118  else
119  j = mIndex + 103;
120 
121  mNumberU = mBuffer[mIndex] ^= mBuffer[j];
122 
123  if (mIndex > 248) /* Increment pointer for next time */
124  mIndex = 0;
125  else
126  mIndex++;
127 
128  return mNumberU;
129 }
#define C_INT16
Definition: copasi.h:91
C_INT32 mIndex
Definition: Cr250.h:30
unsigned C_INT16 mBuffer[250]
Definition: Cr250.h:34
unsigned C_INT32 mNumberU
Definition: CRandom.h:78
unsigned C_INT32 Cr250::r250n ( const unsigned C_INT16 max)
private

Number returned by r250() is in the interval 0 <= k < max.

Parameters
unsignedC_INT16 max
Returns
unsigned C_INT32 random

Definition at line 131 of file Cr250.cpp.

References C_INT16, max, CRandom::mNumberU, and r250().

132 {
133  register unsigned C_INT16 limit;
134 
135  limit = (65535U / max) * max;
136 
137  do
138  {
139  r250();
140  r250(); // Why a second call?
141  }
142  while (mNumberU >= limit);
143 
144  return mNumberU % max;
145 }
unsigned C_INT32 r250(void)
Definition: Cr250.cpp:112
#define C_INT16
Definition: copasi.h:91
unsigned C_INT32 mNumberU
Definition: CRandom.h:78
#define max(a, b)
Definition: f2c.h:176

Friends And Related Function Documentation

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

Member Data Documentation

unsigned C_INT16 Cr250::mBuffer[250]
private

Definition at line 34 of file Cr250.h.

Referenced by initialize(), and r250().

C_INT32 Cr250::mIndex
private

Definition at line 30 of file Cr250.h.

Referenced by initialize(), and r250().

unsigned C_INT32 Cr250::mSeed
private

Definition at line 32 of file Cr250.h.

Referenced by initialize(), and myrand().


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