Debian Codegraph @

external/gsl/gsl_rng__mrg.c

raw symbols SCIP
1 /* rng/mrg.c
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 James Theiler, Brian Gough
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/
21 #include <stdlib.h>
22 #include "gsl_rng.h"cxx . . $ `<file>/external/gsl/gsl_rng.h`/
23
24 /* This is a fifth-order multiple recursive generator. The sequence is,
25
26 x_n = (a_1 x_{n-1} + a_5 x_{n-5}) mod m
27
28 with a_1 = 107374182, a_2 = a_3 = a_4 = 0, a_5 = 104480 and m = 2^31-1.
29
30 We initialize the generator with x_n = s_n MOD m for n = 1..5,
31 where s_n = (69069 * s_{n-1}) mod 2^32, and s_0 = s is the
32 user-supplied seed.
33
34 NOTE: According to the paper the seeds must lie in the range [0,
35 2^31 - 2] with at least one non-zero value -- our seeding procedure
36 satisfies these constraints.
37
38 We then use 6 iterations of the generator to "warm up" the internal
39 state.
40
41 With this initialization procedure the theoretical value of
42 z_{10006} is 2064828650 for s = 1. The subscript 10006 means (1)
43 seed the generator with s = 1, (2) do the 6 warm-up iterations
44 that are part of the seeding process, (3) then do 10000 actual
45 iterations.
46
47 The period of this generator is about 2^155.
48
49 From: P. L'Ecuyer, F. Blouin, and R. Coutre, "A search for good
50 multiple recursive random number generators", ACM Transactions on
51 Modeling and Computer Simulation 3, 87-98 (1993). */
52
53 static inline unsigned long int mrg_getcxx . . $ mrg_get(751e5d26f8574c32). (void *vstate);
54 static double mrg_get_doublecxx . . $ mrg_get_double(a405b17f82753acc). (void *vstate);
55 static void mrg_setcxx . . $ mrg_set(5500c4293b1bbef0). (void *state, unsigned long int s);
56
57 static const long int mcxx . . $ m. = 2147483647;
58 static const long int a1cxx . . $ a1. = 107374182, q1cxx . . $ q1. = 20, r1cxx . . $ r1. = 7;
59 static const long int a5cxx . . $ a5. = 104480, q5cxx . . $ q5. = 20554, r5cxx . . $ r5. = 1727;
60
61 typedef structcxx . . $ $anonymous_type_768f3a3bb482ffaf_0#
62 {
63 long int x1cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x1., x2cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x2., x3cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x3., x4cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x4., x5cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x5.;
64 }
65 mrg_state_tcxx . . $ mrg_state_t#;
66
67 static inline unsigned long int
68 mrg_getcxx . . $ mrg_get(751e5d26f8574c32). (void *vstate)
69 {
70 mrg_state_tcxx . . $ mrg_state_t# *state = (mrg_state_tcxx . . $ mrg_state_t# *) vstate;
71
72 long int p1, h1, p5, h5;
73
74 h5 = state->x5cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x5. / q5cxx . . $ q5.;
75 p5 = a5cxx . . $ a5. * (state->x5cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x5. - h5 * q5cxx . . $ q5.) - h5 * r5cxx . . $ r5.;
76 if (p5 > 0)
77 p5 -= mcxx . . $ m.;
78
79 h1 = state->x1cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x1. / q1cxx . . $ q1.;
80 p1 = a1cxx . . $ a1. * (state->x1cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x1. - h1 * q1cxx . . $ q1.) - h1 * r1cxx . . $ r1.;
81 if (p1 < 0)
82 p1 += mcxx . . $ m.;
83
84 state->x5cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x5. = state->x4cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x4.;
85 state->x4cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x4. = state->x3cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x3.;
86 state->x3cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x3. = state->x2cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x2.;
87 state->x2cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x2. = state->x1cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x1.;
88
89 state->x1cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x1. = p1 + p5;
90
91 if (state->x1cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x1. < 0)
92 state->x1cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x1. += mcxx . . $ m.;
93
94 return state->x1cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x1.;
95 }
96
97 static double
98 mrg_get_doublecxx . . $ mrg_get_double(a405b17f82753acc). (void *vstate)
99 {
100 return mrg_getcxx . . $ mrg_get(751e5d26f8574c32). (vstate) / 2147483647.0 ;
101 }
102
103
104 static void
105 mrg_setcxx . . $ mrg_set(5500c4293b1bbef0). (void *vstate, unsigned long int s)
106 {
107 /* An entirely adhoc way of seeding! This does **not** come from
108 L'Ecuyer et al */
109
110 mrg_state_tcxx . . $ mrg_state_t# *state = (mrg_state_tcxx . . $ mrg_state_t# *) vstate;
111
112 if (s == 0)
113 s = 1; /* default seed is 1 */
114
115 #define LCGcxx . . $ `external/gsl/gsl_rng__mrg.c:115:9`!(n) ((69069 * n) & 0xffffffffUL)
116 s = LCGcxx . . $ `external/gsl/gsl_rng__mrg.c:115:9`! (s);
117 state->x1cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x1. = s % mcxx . . $ m.;
118 s = LCGcxx . . $ `external/gsl/gsl_rng__mrg.c:115:9`! (s);
119 state->x2cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x2. = s % mcxx . . $ m.;
120 s = LCGcxx . . $ `external/gsl/gsl_rng__mrg.c:115:9`! (s);
121 state->x3cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x3. = s % mcxx . . $ m.;
122 s = LCGcxx . . $ `external/gsl/gsl_rng__mrg.c:115:9`! (s);
123 state->x4cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x4. = s % mcxx . . $ m.;
124 s = LCGcxx . . $ `external/gsl/gsl_rng__mrg.c:115:9`! (s);
125 state->x5cxx . . $ $anonymous_type_768f3a3bb482ffaf_0#x5. = s % mcxx . . $ m.;
126
127 /* "warm it up" with at least 5 calls to go through
128 all the x values */
129
130 mrg_getcxx . . $ mrg_get(751e5d26f8574c32). (state);
131 mrg_getcxx . . $ mrg_get(751e5d26f8574c32). (state);
132 mrg_getcxx . . $ mrg_get(751e5d26f8574c32). (state);
133 mrg_getcxx . . $ mrg_get(751e5d26f8574c32). (state);
134 mrg_getcxx . . $ mrg_get(751e5d26f8574c32). (state);
135 mrg_getcxx . . $ mrg_get(751e5d26f8574c32). (state);
136
137 return;
138 }
139
140 static const gsl_rng_typecxx . . $ gsl_rng_type# mrg_typecxx . . $ mrg_type. =
141 {"mrg", /* name */
142 2147483646, /* RAND_MAX */
143 0, /* RAND_MIN */
144 sizeof (mrg_state_tcxx . . $ mrg_state_t#),
145 &mrg_setcxx . . $ mrg_set(5500c4293b1bbef0).,
146 &mrg_getcxx . . $ mrg_get(751e5d26f8574c32).,
147 &mrg_get_doublecxx . . $ mrg_get_double(a405b17f82753acc).};
148
149 const gsl_rng_typecxx . . $ gsl_rng_type# *gsl_rng_mrgcxx . . $ gsl_rng_mrg. = &mrg_typecxx . . $ mrg_type.;