COPASI API  4.16.103
Cmt19937.h
Go to the documentation of this file.
1 /* Begin CVS Header
2  $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/randomGenerator/Cmt19937.h,v $
3  $Revision: 1.7 $
4  $Name: $
5  $Author: shoops $
6  $Date: 2006/07/21 18:15:48 $
7  End CVS Header */
8 
9 // Copyright 2005 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc. and EML Research, gGmbH.
11 // All rights reserved.
12 
13 /**
14  * Cmt19937 class implementing the Mersenne Twister random number generator,
15  *
16  * Created for Copasi by Stefan Hoops
17  *
18  * A C-program for MT19937, with initialization improved 2002/2/10.
19  * Coded by Takuji Nishimura and Makoto Matsumoto.
20  * This is a faster version by taking Shawn Cokus's optimization,
21  * Matthe Bellew's simplification, Isaku Wada's real version.
22  *
23  * Before using, initialize the state by using init_genrand(seed)
24  * or init_by_array(init_key, key_length).
25  *
26  * Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without
30  * modification, are permitted provided that the following conditions
31  * are met:
32  *
33  * 1. Redistributions of source code must retain the above copyright
34  * notice, this list of conditions and the following disclaimer.
35  *
36  * 2. Redistributions in binary form must reproduce the above copyright
37  * notice, this list of conditions and the following disclaimer in the
38  * documentation and/or other materials provided with the distribution.
39  *
40  * 3. The names of its contributors may not be used to endorse or promote
41  * products derived from this software without specific prior written
42  * permission.
43  *
44  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
45  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
46  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
47  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
48  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
49  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
50  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
51  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
52  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
53  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
54  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55  *
56  *
57  * Any feedback is very welcome.
58  * http://www.math.keio.ac.jp/matumoto/emt.html
59  * email: matumoto@math.keio.ac.jp
60  */
61 
62 #ifndef COPASI_Cmt19937
63 #define COPASI_Cmt19937
64 
65 #define Cmt19937_N 624
66 
67 class Cmt19937 : public CRandom
68  {
70  unsigned C_INT32 seed);
71 
72  // Attributes
73  private:
74  unsigned C_INT32 mState[Cmt19937_N]; /* the array for the state vector */
75 
76  C_INT mLeft; // = 1;
77 
78  unsigned C_INT32 *mNext;
79 
80  // Operations
81  protected:
82  /**
83  * Default/Named constructor.
84  * Seeds the random number generator with the given seed.
85  * @param C_INT32 seed
86  */
87  Cmt19937(unsigned C_INT32 seed);
88 
89  void next_state();
90 
91  public:
92  /**
93  * The destructor.
94  */
95  ~Cmt19937();
96 
97  /**
98  * Initialize or reinitialize the random number generator with
99  * the given seed.
100  * @param unsigned C_INT32 seed (default system seed)
101  */
102  void initialize(unsigned C_INT32 seed = CRandom::getSystemSeed());
103 
104  /**
105  * Get a random number in 0 <= n <= Modulus
106  * @return unsigned C_INT32 random
107  */
108  unsigned C_INT32 getRandomU();
109 
110  /**
111  * Get a random number in 0 <= n <= (Modulus & 0x7ffffff)
112  * @return C_INT32 random
113  */
115 
116  /**
117  * Produces a uniformly distributed random number in 0 <= x <= 1.
118  * @return C_FLOAT64 random
119  */
121 
122  /**
123  * Produces a uniformly distributed random number in 0 <= x < 1.
124  * Note: 0 < x <= 1 may be achieved by 1.0 - getRandomCO().
125  * @return C_FLOAT64 random
126  */
128 
129  /**
130  * Produces a uniformly distributed random number in 0 < x < 1.
131  * @return C_FLOAT64 random
132  */
134 
135  void init_by_array(unsigned C_INT32 init_key[],
136  C_INT32 key_length);
137 
138  C_FLOAT64 genrand_res53(); // getRandomCO() with higher resolution
139  };
140 
141 class Cmt19937HR : public Cmt19937
142  {
144  unsigned C_INT32 seed);
145 
146  // Operations
147  protected:
148  /**
149  * Default/Named constructor.
150  * Seeds the random number generator with the given seed.
151  * @param C_INT32 seed
152  */
153  Cmt19937HR(unsigned C_INT32 seed);
154 
155  public:
156  /**
157  * Produces a uniformly distributed random number in 0 <= x <= 1.
158  * @return C_FLOAT64 random
159  */
161 
162  /**
163  * Produces a uniformly distributed random number in 0 <= x < 1.
164  * Note: 0 < x <= 1 may be achieved by 1.0 - getRandomCO().
165  * @return C_FLOAT64 random
166  */
168 
169  /**
170  * Produces a uniformly distributed random number in 0 < x < 1.
171  * @return C_FLOAT64 random
172  */
174  };
175 
176 #endif // COPASI_Cmt19937
#define C_INT
Definition: copasi.h:115
static unsigned C_INT32 getSystemSeed()
Definition: CRandom.cpp:136
Cmt19937HR(unsigned C_INT32 seed)
Definition: Cmt19937.cpp:248
C_FLOAT64 getRandomOO()
Definition: Cmt19937.cpp:267
Cmt19937(unsigned C_INT32 seed)
Definition: Cmt19937.cpp:75
C_FLOAT64 getRandomCO()
Definition: Cmt19937.cpp:260
void initialize(unsigned C_INT32 seed=CRandom::getSystemSeed())
Definition: Cmt19937.cpp:87
unsigned C_INT32 mState[624]
Definition: Cmt19937.h:74
#define C_INT32
Definition: copasi.h:90
~Cmt19937()
Definition: Cmt19937.cpp:84
void init_by_array(unsigned C_INT32 init_key[], C_INT32 key_length)
Definition: Cmt19937.cpp:106
C_FLOAT64 getRandomCO()
Definition: Cmt19937.cpp:207
C_FLOAT64 getRandomCC()
Definition: Cmt19937.cpp:253
static CRandom * createGenerator(CRandom::Type type=CRandom::mt19937, unsigned C_INT32 seed=0)
Definition: CRandom.cpp:49
C_FLOAT64 getRandomOO()
Definition: Cmt19937.cpp:224
unsigned C_INT32 getRandomU()
Definition: Cmt19937.cpp:158
C_FLOAT64 getRandomCC()
Definition: Cmt19937.cpp:190
void next_state()
Definition: Cmt19937.cpp:140
#define C_FLOAT64
Definition: copasi.h:92
unsigned C_INT32 * mNext
Definition: Cmt19937.h:78
#define Cmt19937_N
Definition: Cmt19937.h:65
C_FLOAT64 genrand_res53()
Definition: Cmt19937.cpp:241
C_INT32 getRandomS()
Definition: Cmt19937.cpp:174
C_INT mLeft
Definition: Cmt19937.h:76