tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mt19937ar.h
Go to the documentation of this file.
1 /* =============================================================================
2  *
3  * mt19937ar.h
4  * -- MT19937 random number generator
5  *
6  * =============================================================================
7  *
8  * A C-program for MT19937, with initialization improved 2002/1/26.
9  * Coded by Takuji Nishimura and Makoto Matsumoto.
10  *
11  * Before using, initialize the state by using init_genrand(seed)
12  * or init_by_array(init_key, key_length).
13  *
14  * Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  *
21  * 1. Redistributions of source code must retain the above copyright
22  * notice, this list of conditions and the following disclaimer.
23  *
24  * 2. Redistributions in binary form must reproduce the above copyright
25  * notice, this list of conditions and the following disclaimer in the
26  * documentation and/or other materials provided with the distribution.
27  *
28  * 3. The names of its contributors may not be used to endorse or promote
29  * products derived from this software without specific prior written
30  * permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
36  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
37  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
38  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
39  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
40  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43  *
44  *
45  * Any feedback is very welcome.
46  * http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
47  * email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
48  *
49  * =============================================================================
50  *
51  * Modified February 2006 by Chi Cao Minh
52  *
53  * - Changed functions to take 'mt' and 'mti' as arguments so can have
54  * private per-thread random number generators.
55  *
56  * =============================================================================
57  *
58  * For the license of bayes/sort.h and bayes/sort.c, please see the header
59  * of the files.
60  *
61  * ------------------------------------------------------------------------
62  *
63  * For the license of kmeans, please see kmeans/LICENSE.kmeans
64  *
65  * ------------------------------------------------------------------------
66  *
67  * For the license of ssca2, please see ssca2/COPYRIGHT
68  *
69  * ------------------------------------------------------------------------
70  *
71  * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the
72  * header of the files.
73  *
74  * ------------------------------------------------------------------------
75  *
76  * For the license of lib/rbtree.h and lib/rbtree.c, please see
77  * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree
78  *
79  * ------------------------------------------------------------------------
80  *
81  * Unless otherwise noted, the following license applies to STAMP files:
82  *
83  * Copyright (c) 2007, Stanford University
84  * All rights reserved.
85  *
86  * Redistribution and use in source and binary forms, with or without
87  * modification, are permitted provided that the following conditions are
88  * met:
89  *
90  * * Redistributions of source code must retain the above copyright
91  * notice, this list of conditions and the following disclaimer.
92  *
93  * * Redistributions in binary form must reproduce the above copyright
94  * notice, this list of conditions and the following disclaimer in
95  * the documentation and/or other materials provided with the
96  * distribution.
97  *
98  * * Neither the name of Stanford University nor the names of its
99  * contributors may be used to endorse or promote products derived
100  * from this software without specific prior written permission.
101  *
102  * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
103  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
104  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
105  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
106  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
107  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
108  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
109  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
110  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
111  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
112  * THE POSSIBILITY OF SUCH DAMAGE.
113  *
114  * =============================================================================
115  */
116 
117 
118 
119 #include <stdio.h>
120 
121 
122 
123 #ifndef MT19937AR_H
124 #define MT19937AR_H 1
125 
126 
127 
128 #ifdef __cplusplus
129 extern "C" {
130 #endif
131 
132 
133 
134 /* Period parameters */
135 #define N 624
136 #define M 397
137 #define MATRIX_A 0x9908b0dfUL /* constant vector a */
138 #define UPPER_MASK 0x80000000UL /* most significant w-r bits */
139 #define LOWER_MASK 0x7fffffffUL /* least significant r bits */
140 
141 #if 0
142 static unsigned long mt[N]; /* the array for the state vector */
143 static long mti=N+1; /* mti==N+1 means mt[N] is not initialized */
144 #endif
145 
146 /* initializes mt[N] with a seed */
147 void init_genrand(unsigned long mt[], unsigned long * mtiPtr, unsigned long s);
148 
149 /* initialize by an array with array-length */
150 /* init_key is the array for initializing keys */
151 /* key_length is its length */
152 /* slight change for C++, 2004/2/26 */
153 void init_by_array(unsigned long mt[], unsigned long * mtiPtr, unsigned long init_key[], long key_length);
154 
155 /* generates a random number on [0,0xffffffff]-interval */
156 unsigned long genrand_int32(unsigned long mt[], unsigned long * mtiPtr);
157 
158 /* generates a random number on [0,0x7fffffff]-interval */
159 long genrand_int31(unsigned long mt[], unsigned long * mtiPtr);
160 
161 /* generates a random number on [0,1]-real-interval */
162 double genrand_real1(unsigned long mt[], unsigned long * mtiPtr);
163 
164 /* generates a random number on [0,1)-real-interval */
165 double genrand_real2(unsigned long mt[], unsigned long * mtiPtr);
166 /* generates a random number on (0,1)-real-interval */
167 double genrand_real3(unsigned long mt[], unsigned long * mtiPtr);
168 
169 /* generates a random number on [0,1) with 53-bit resolution*/
170 double genrand_res53(unsigned long mt[], unsigned long * mtiPtr);
171 
172 
173 
174 #ifdef __cplusplus
175 }
176 #endif
177 
178 
179 
180 #endif /* MT19937AR_H */
181 
182 
183 /* =============================================================================
184  *
185  * End of mt19937ar.h
186  *
187  * =============================================================================
188  */
double genrand_real2(unsigned long mt[], unsigned long *mtiPtr)
Definition: mt19937ar.c:227
long genrand_int31(unsigned long mt[], unsigned long *mtiPtr)
Definition: mt19937ar.c:214
#define N
Definition: mt19937ar.h:135
double genrand_real3(unsigned long mt[], unsigned long *mtiPtr)
Definition: mt19937ar.c:234
double genrand_res53(unsigned long mt[], unsigned long *mtiPtr)
Definition: mt19937ar.c:241
void init_genrand(unsigned long mt[], unsigned long *mtiPtr, unsigned long s)
Definition: mt19937ar.c:122
unsigned long genrand_int32(unsigned long mt[], unsigned long *mtiPtr)
Definition: mt19937ar.c:172
double genrand_real1(unsigned long mt[], unsigned long *mtiPtr)
Definition: mt19937ar.c:220
void init_by_array(unsigned long mt[], unsigned long *mtiPtr, unsigned long init_key[], long key_length)
Definition: mt19937ar.c:145