Debian Codegraph @

external/gsl/gsl_rng__ran0.c

raw symbols SCIP
1 /* rng/ran0.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_errno.h"cxx . . $ `<file>/external/gsl/gsl_errno.h`/
23 #include "gsl_rng.h"cxx . . $ `<file>/external/gsl/gsl_rng.h`/
24
25 /* This is an implementation of the algorithm used in Numerical
26 Recipe's ran0 generator. It is the same as MINSTD with an XOR mask
27 of 123459876 on the seed.
28
29 The period of this generator is 2^31.
30
31 Note, if you choose a seed of 123459876 it would give a degenerate
32 series 0,0,0,0, ... I've made that into an error. */
33
34 static inline unsigned long int ran0_getcxx . . $ ran0_get(751e5d26f8574c32). (void *vstate);
35 static double ran0_get_doublecxx . . $ ran0_get_double(a405b17f82753acc). (void *vstate);
36 static void ran0_setcxx . . $ ran0_set(5500c4293b1bbef0). (void *state, unsigned long int s);
37
38 static const long int mcxx . . $ m. = 2147483647, acxx . . $ a. = 16807, qcxx . . $ q. = 127773, rcxx . . $ r. = 2836;
39 static const unsigned long int maskcxx . . $ mask. = 123459876;
40
41 typedef structcxx . . $ $anonymous_type_b02733724e580dca_0#
42 {
43 unsigned long int xcxx . . $ $anonymous_type_b02733724e580dca_0#x.;
44 }
45 ran0_state_tcxx . . $ ran0_state_t#;
46
47 static inline unsigned long int
48 ran0_getcxx . . $ ran0_get(751e5d26f8574c32). (void *vstate)
49 {
50 ran0_state_tcxx . . $ ran0_state_t# *state = (ran0_state_tcxx . . $ ran0_state_t# *) vstate;
51
52 const unsigned long int x = state->xcxx . . $ $anonymous_type_b02733724e580dca_0#x.;
53
54 const long int h = x / qcxx . . $ q.;
55 const long int t = acxx . . $ a. * (x - h * qcxx . . $ q.) - h * rcxx . . $ r.;
56
57 if (t < 0)
58 {
59 state->xcxx . . $ $anonymous_type_b02733724e580dca_0#x. = t + mcxx . . $ m.;
60 }
61 else
62 {
63 state->xcxx . . $ $anonymous_type_b02733724e580dca_0#x. = t;
64 }
65
66 return state->xcxx . . $ $anonymous_type_b02733724e580dca_0#x.;
67 }
68
69 static double
70 ran0_get_doublecxx . . $ ran0_get_double(a405b17f82753acc). (void *vstate)
71 {
72 return ran0_getcxx . . $ ran0_get(751e5d26f8574c32). (vstate) / 2147483647.0 ;
73 }
74
75 static void
76 ran0_setcxx . . $ ran0_set(5500c4293b1bbef0). (void *vstate, unsigned long int s)
77 {
78 ran0_state_tcxx . . $ ran0_state_t# *state = (ran0_state_tcxx . . $ ran0_state_t# *) vstate;
79
80 if (s == maskcxx . . $ mask.)
81 {
82 GSL_ERROR_VOIDcxx . . $ `external/gsl/gsl_errno.h:121:9`! ("ran0 should not use seed == mask",
83 GSL_EINVAL);
84 }
85
86 state->xcxx . . $ $anonymous_type_b02733724e580dca_0#x. = s ^ maskcxx . . $ mask.;
87
88 return;
89 }
90
91 static const gsl_rng_typecxx . . $ gsl_rng_type# ran0_typecxx . . $ ran0_type. =
92 {"ran0", /* name */
93 2147483646, /* RAND_MAX */
94 1, /* RAND_MIN */
95 sizeof (ran0_state_tcxx . . $ ran0_state_t#),
96 &ran0_setcxx . . $ ran0_set(5500c4293b1bbef0).,
97 &ran0_getcxx . . $ ran0_get(751e5d26f8574c32).,
98 &ran0_get_doublecxx . . $ ran0_get_double(a405b17f82753acc).};
99
100 const gsl_rng_typecxx . . $ gsl_rng_type# *gsl_rng_ran0cxx . . $ gsl_rng_ran0. = &ran0_typecxx . . $ ran0_type.;