Debian Codegraph @

external/gsl/gsl_rng__mt.c

raw symbols SCIP
1 /* This program is free software; you can redistribute it and/or
2 modify it under the terms of the GNU General Public License as
3 published by the Free Software Foundation; either version 3 of the
4 License, or (at your option) any later version.
5
6 This program is distributed in the hope that it will be useful, but
7 WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 General Public License for more details. You should have received
10 a copy of the GNU General Public License along with this program;
11 if not, write to the Free Foundation, Inc., 59 Temple Place, Suite
12 330, Boston, MA 02111-1307 USA
13
14 Original implementation was copyright (C) 1997 Makoto Matsumoto and
15 Takuji Nishimura. Coded by Takuji Nishimura, considering the
16 suggestions by Topher Cooper and Marc Rieffel in July-Aug. 1997, "A
17 C-program for MT19937: Integer version (1998/4/6)"
18
19 This implementation copyright (C) 1998 Brian Gough. I reorganized
20 the code to use the module framework of GSL. The license on this
21 implementation was changed from LGPL to GPL, following paragraph 3
22 of the LGPL, version 2.
23
24 Update:
25
26 The seeding procedure has been updated to match the 10/99 release
27 of MT19937.
28
29 Update:
30
31 The seeding procedure has been updated again to match the 2002
32 release of MT19937
33
34 The original code included the comment: "When you use this, send an
35 email to: [email protected] with an appropriate reference to
36 your work".
37
38 Makoto Matsumoto has a web page with more information about the
39 generator, http://www.math.keio.ac.jp/~matumoto/emt.html.
40
41 The paper below has details of the algorithm.
42
43 From: Makoto Matsumoto and Takuji Nishimura, "Mersenne Twister: A
44 623-dimensionally equidistributerd uniform pseudorandom number
45 generator". ACM Transactions on Modeling and Computer Simulation,
46 Vol. 8, No. 1 (Jan. 1998), Pages 3-30
47
48 You can obtain the paper directly from Makoto Matsumoto's web page.
49
50 The period of this generator is 2^{19937} - 1.
51
52 */
53
54 #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/
55 #include <stdlib.h>
56 #include "gsl_rng.h"cxx . . $ `<file>/external/gsl/gsl_rng.h`/
57
58 static inline unsigned long int mt_getcxx . . $ mt_get(751e5d26f8574c32). (void *vstate);
59 static double mt_get_doublecxx . . $ mt_get_double(a405b17f82753acc). (void *vstate);
60 static void mt_setcxx . . $ mt_set(5500c4293b1bbef0). (void *state, unsigned long int s);
61
62 #define Ncxx . . $ `external/gsl/gsl_rng__mt.c:62:9`! 624 /* Period parameters */
63 #define Mcxx . . $ `external/gsl/gsl_rng__mt.c:63:9`! 397
64
65 /* most significant w-r bits */
66 static const unsigned long UPPER_MASKcxx . . $ UPPER_MASK. = 0x80000000UL;
67
68 /* least significant r bits */
69 static const unsigned long LOWER_MASKcxx . . $ LOWER_MASK. = 0x7fffffffUL;
70
71 typedef structcxx . . $ $anonymous_type_78f6080165613772_0#
72 {
73 unsigned long mtcxx . . $ $anonymous_type_78f6080165613772_0#mt.[Ncxx . . $ `external/gsl/gsl_rng__mt.c:62:9`!];
74 int mticxx . . $ $anonymous_type_78f6080165613772_0#mti.;
75 }
76 mt_state_tcxx . . $ mt_state_t#;
77
78 static inline unsigned long
79 mt_getcxx . . $ mt_get(751e5d26f8574c32). (void *vstate)
80 {
81 mt_state_tcxx . . $ mt_state_t# *state = (mt_state_tcxx . . $ mt_state_t# *) vstate;
82
83 unsigned long k ;
84 unsigned long int *const mt = state->mtcxx . . $ $anonymous_type_78f6080165613772_0#mt.;
85
86 #define MAGICcxx . . $ `external/gsl/gsl_rng__mt.c:86:9`!(y) (((y)&0x1) ? 0x9908b0dfUL : 0)
87
88 if (state->mticxx . . $ $anonymous_type_78f6080165613772_0#mti. >= Ncxx . . $ `external/gsl/gsl_rng__mt.c:62:9`!)
89 { /* generate N words at one time */
90 int kk;
91
92 for (kk = 0; kk < Ncxx . . $ `external/gsl/gsl_rng__mt.c:62:9`! - Mcxx . . $ `external/gsl/gsl_rng__mt.c:63:9`!; kk++)
93 {
94 unsigned long y = (mt[kk] & UPPER_MASKcxx . . $ UPPER_MASK.) | (mt[kk + 1] & LOWER_MASKcxx . . $ LOWER_MASK.);
95 mt[kk] = mt[kk + Mcxx . . $ `external/gsl/gsl_rng__mt.c:63:9`!] ^ (y >> 1) ^ MAGICcxx . . $ `external/gsl/gsl_rng__mt.c:86:9`!(y);
96 }
97 for (; kk < Ncxx . . $ `external/gsl/gsl_rng__mt.c:62:9`! - 1; kk++)
98 {
99 unsigned long y = (mt[kk] & UPPER_MASKcxx . . $ UPPER_MASK.) | (mt[kk + 1] & LOWER_MASKcxx . . $ LOWER_MASK.);
100 mt[kk] = mt[kk + (Mcxx . . $ `external/gsl/gsl_rng__mt.c:63:9`! - Ncxx . . $ `external/gsl/gsl_rng__mt.c:62:9`!)] ^ (y >> 1) ^ MAGICcxx . . $ `external/gsl/gsl_rng__mt.c:86:9`!(y);
101 }
102
103 {
104 unsigned long y = (mt[Ncxx . . $ `external/gsl/gsl_rng__mt.c:62:9`! - 1] & UPPER_MASKcxx . . $ UPPER_MASK.) | (mt[0] & LOWER_MASKcxx . . $ LOWER_MASK.);
105 mt[Ncxx . . $ `external/gsl/gsl_rng__mt.c:62:9`! - 1] = mt[Mcxx . . $ `external/gsl/gsl_rng__mt.c:63:9`! - 1] ^ (y >> 1) ^ MAGICcxx . . $ `external/gsl/gsl_rng__mt.c:86:9`!(y);
106 }
107
108 state->mticxx . . $ $anonymous_type_78f6080165613772_0#mti. = 0;
109 }
110
111 /* Tempering */
112
113 k = mt[state->mticxx . . $ $anonymous_type_78f6080165613772_0#mti.];
114 k ^= (k >> 11);
115 k ^= (k << 7) & 0x9d2c5680UL;
116 k ^= (k << 15) & 0xefc60000UL;
117 k ^= (k >> 18);
118
119 state->mticxx . . $ $anonymous_type_78f6080165613772_0#mti.++;
120
121 return k;
122 }
123
124 static double
125 mt_get_doublecxx . . $ mt_get_double(a405b17f82753acc). (void * vstate)
126 {
127 return mt_getcxx . . $ mt_get(751e5d26f8574c32). (vstate) / 4294967296.0 ;
128 }
129
130 static void
131 mt_setcxx . . $ mt_set(5500c4293b1bbef0). (void *vstate, unsigned long int s)
132 {
133 mt_state_tcxx . . $ mt_state_t# *state = (mt_state_tcxx . . $ mt_state_t# *) vstate;
134 int i;
135
136 if (s == 0)
137 s = 4357; /* the default seed is 4357 */
138
139 state->mtcxx . . $ $anonymous_type_78f6080165613772_0#mt.[0]= s & 0xffffffffUL;
140
141 for (i = 1; i < Ncxx . . $ `external/gsl/gsl_rng__mt.c:62:9`!; i++)
142 {
143 /* See Knuth's "Art of Computer Programming" Vol. 2, 3rd
144 Ed. p.106 for multiplier. */
145
146 state->mtcxx . . $ $anonymous_type_78f6080165613772_0#mt.[i] =
147 (1812433253UL * (state->mtcxx . . $ $anonymous_type_78f6080165613772_0#mt.[i-1] ^ (state->mtcxx . . $ $anonymous_type_78f6080165613772_0#mt.[i-1] >> 30)) + i);
148
149 state->mtcxx . . $ $anonymous_type_78f6080165613772_0#mt.[i] &= 0xffffffffUL;
150 }
151
152 state->mticxx . . $ $anonymous_type_78f6080165613772_0#mti. = i;
153 }
154
155 static void
156 mt_1999_setcxx . . $ mt_1999_set(5500c4293b1bbef0). (void *vstate, unsigned long int s)
157 {
158 mt_state_tcxx . . $ mt_state_t# *state = (mt_state_tcxx . . $ mt_state_t# *) vstate;
159 int i;
160
161 if (s == 0)
162 s = 4357; /* the default seed is 4357 */
163
164 /* This is the October 1999 version of the seeding procedure. It
165 was updated by the original developers to avoid the periodicity
166 in the simple congruence originally used.
167
168 Note that an ANSI-C unsigned long integer arithmetic is
169 automatically modulo 2^32 (or a higher power of two), so we can
170 safely ignore overflow. */
171
172 #define LCGcxx . . $ `external/gsl/gsl_rng__mt.c:172:9`!(x) ((69069 * x) + 1) &0xffffffffUL
173
174 for (i = 0; i < Ncxx . . $ `external/gsl/gsl_rng__mt.c:62:9`!; i++)
175 {
176 state->mtcxx . . $ $anonymous_type_78f6080165613772_0#mt.[i] = s & 0xffff0000UL;
177 s = LCGcxx . . $ `external/gsl/gsl_rng__mt.c:172:9`!(s);
178 state->mtcxx . . $ $anonymous_type_78f6080165613772_0#mt.[i] |= (s &0xffff0000UL) >> 16;
179 s = LCGcxx . . $ `external/gsl/gsl_rng__mt.c:172:9`!(s);
180 }
181
182 state->mticxx . . $ $anonymous_type_78f6080165613772_0#mti. = i;
183 }
184
185 /* This is the original version of the seeding procedure, no longer
186 used but available for compatibility with the original MT19937. */
187
188 static void
189 mt_1998_setcxx . . $ mt_1998_set(5500c4293b1bbef0). (void *vstate, unsigned long int s)
190 {
191 mt_state_tcxx . . $ mt_state_t# *state = (mt_state_tcxx . . $ mt_state_t# *) vstate;
192 int i;
193
194 if (s == 0)
195 s = 4357; /* the default seed is 4357 */
196
197 state->mtcxx . . $ $anonymous_type_78f6080165613772_0#mt.[0] = s & 0xffffffffUL;
198
199 #define LCG1998cxx . . $ `external/gsl/gsl_rng__mt.c:199:9`!(n) ((69069 * n) & 0xffffffffUL)
200
201 for (i = 1; i < Ncxx . . $ `external/gsl/gsl_rng__mt.c:62:9`!; i++)
202 state->mtcxx . . $ $anonymous_type_78f6080165613772_0#mt.[i] = LCG1998cxx . . $ `external/gsl/gsl_rng__mt.c:199:9`! (state->mt[i - 1]);
203
204 state->mticxx . . $ $anonymous_type_78f6080165613772_0#mti. = i;
205 }
206
207 static const gsl_rng_typecxx . . $ gsl_rng_type# mt_typecxx . . $ mt_type. =
208 {"mt19937", /* name */
209 0xffffffffUL, /* RAND_MAX */
210 0, /* RAND_MIN */
211 sizeof (mt_state_tcxx . . $ mt_state_t#),
212 &mt_setcxx . . $ mt_set(5500c4293b1bbef0).,
213 &mt_getcxx . . $ mt_get(751e5d26f8574c32).,
214 &mt_get_doublecxx . . $ mt_get_double(a405b17f82753acc).};
215
216 static const gsl_rng_typecxx . . $ gsl_rng_type# mt_1999_typecxx . . $ mt_1999_type. =
217 {"mt19937_1999", /* name */
218 0xffffffffUL, /* RAND_MAX */
219 0, /* RAND_MIN */
220 sizeof (mt_state_tcxx . . $ mt_state_t#),
221 &mt_1999_setcxx . . $ mt_1999_set(5500c4293b1bbef0).,
222 &mt_getcxx . . $ mt_get(751e5d26f8574c32).,
223 &mt_get_doublecxx . . $ mt_get_double(a405b17f82753acc).};
224
225 static const gsl_rng_typecxx . . $ gsl_rng_type# mt_1998_typecxx . . $ mt_1998_type. =
226 {"mt19937_1998", /* name */
227 0xffffffffUL, /* RAND_MAX */
228 0, /* RAND_MIN */
229 sizeof (mt_state_tcxx . . $ mt_state_t#),
230 &mt_1998_setcxx . . $ mt_1998_set(5500c4293b1bbef0).,
231 &mt_getcxx . . $ mt_get(751e5d26f8574c32).,
232 &mt_get_doublecxx . . $ mt_get_double(a405b17f82753acc).};
233
234 const gsl_rng_typecxx . . $ gsl_rng_type# *gsl_rng_mt19937cxx . . $ gsl_rng_mt19937. = &mt_typecxx . . $ mt_type.;
235 const gsl_rng_typecxx . . $ gsl_rng_type# *gsl_rng_mt19937_1999cxx . . $ gsl_rng_mt19937_1999. = &mt_1999_typecxx . . $ mt_1999_type.;
236 const gsl_rng_typecxx . . $ gsl_rng_type# *gsl_rng_mt19937_1998cxx . . $ gsl_rng_mt19937_1998. = &mt_1998_typecxx . . $ mt_1998_type.;
237
238 /* MT19937 is the default generator, so define that here too */
239
240 const gsl_rng_typecxx . . $ gsl_rng_type# *gsl_rng_defaultcxx . . $ gsl_rng_default. = &mt_typecxx . . $ mt_type.;
241 unsigned long int gsl_rng_default_seedcxx . . $ gsl_rng_default_seed. = 0;