| 1 | /* rng/ran3.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 an implementation of the algorithm used in Knuths's |
| 25 | subtractive generator, with the Numerical Recipe's ran3 paramters. |
| 26 | It is a subtractive lagged fibonnaci generator. */ |
| 27 | |
| 28 | static inline unsigned long int ran3_getcxx . . $ ran3_get(751e5d26f8574c32). (void *vstate); |
| 29 | static double ran3_get_doublecxx . . $ ran3_get_double(a405b17f82753acc). (void *vstate); |
| 30 | static void ran3_setcxx . . $ ran3_set(5500c4293b1bbef0). (void *state, unsigned long int s); |
| 31 | |
| 32 | #define M_BIGcxx . . $ `external/gsl/gsl_rng__ran3.c:32:9`! 1000000000 |
| 33 | #define M_SEEDcxx . . $ `external/gsl/gsl_rng__ran3.c:33:9`! 161803398 |
| 34 | |
| 35 | typedef structcxx . . $ $anonymous_type_bcc624109a126950_0# |
| 36 | { |
| 37 | unsigned int xcxx . . $ $anonymous_type_bcc624109a126950_0#x.; |
| 38 | unsigned int ycxx . . $ $anonymous_type_bcc624109a126950_0#y.; |
| 39 | unsigned long int buffercxx . . $ $anonymous_type_bcc624109a126950_0#buffer.[56]; |
| 40 | } |
| 41 | ran3_state_tcxx . . $ ran3_state_t#; |
| 42 | |
| 43 | static inline unsigned long int |
| 44 | ran3_getcxx . . $ ran3_get(751e5d26f8574c32). (void *vstate) |
| 45 | { |
| 46 | ran3_state_tcxx . . $ ran3_state_t# *state = (ran3_state_tcxx . . $ ran3_state_t# *) vstate; |
| 47 | long int j; |
| 48 | |
| 49 | state->xcxx . . $ $anonymous_type_bcc624109a126950_0#x.++; |
| 50 | |
| 51 | if (state->xcxx . . $ $anonymous_type_bcc624109a126950_0#x. == 56) |
| 52 | state->xcxx . . $ $anonymous_type_bcc624109a126950_0#x. = 1; |
| 53 | |
| 54 | state->ycxx . . $ $anonymous_type_bcc624109a126950_0#y.++; |
| 55 | |
| 56 | if (state->ycxx . . $ $anonymous_type_bcc624109a126950_0#y. == 56) |
| 57 | state->ycxx . . $ $anonymous_type_bcc624109a126950_0#y. = 1; |
| 58 | |
| 59 | j = state->buffercxx . . $ $anonymous_type_bcc624109a126950_0#buffer.[state->xcxx . . $ $anonymous_type_bcc624109a126950_0#x.] - state->buffercxx . . $ $anonymous_type_bcc624109a126950_0#buffer.[state->ycxx . . $ $anonymous_type_bcc624109a126950_0#y.]; |
| 60 | |
| 61 | if (j < 0) |
| 62 | j += M_BIGcxx . . $ `external/gsl/gsl_rng__ran3.c:32:9`!; |
| 63 | |
| 64 | state->buffercxx . . $ $anonymous_type_bcc624109a126950_0#buffer.[state->xcxx . . $ $anonymous_type_bcc624109a126950_0#x.] = j; |
| 65 | |
| 66 | return j; |
| 67 | } |
| 68 | |
| 69 | static double |
| 70 | ran3_get_doublecxx . . $ ran3_get_double(a405b17f82753acc). (void *vstate) |
| 71 | { |
| 72 | return ran3_getcxx . . $ ran3_get(751e5d26f8574c32). (vstate) / (double) M_BIGcxx . . $ `external/gsl/gsl_rng__ran3.c:32:9`! ; |
| 73 | } |
| 74 | |
| 75 | static void |
| 76 | ran3_setcxx . . $ ran3_set(5500c4293b1bbef0). (void *vstate, unsigned long int s) |
| 77 | { |
| 78 | ran3_state_tcxx . . $ ran3_state_t# *state = (ran3_state_tcxx . . $ ran3_state_t# *) vstate; |
| 79 | int i, i1; |
| 80 | long int j, k; |
| 81 | |
| 82 | if (s == 0) |
| 83 | s = 1; /* default seed is 1 */ |
| 84 | |
| 85 | j = (M_SEEDcxx . . $ `external/gsl/gsl_rng__ran3.c:33:9`! - s) % M_BIGcxx . . $ `external/gsl/gsl_rng__ran3.c:32:9`!; |
| 86 | |
| 87 | /* the zeroth element is never used, but we initialize it for |
| 88 | consistency between states */ |
| 89 | |
| 90 | state->buffercxx . . $ $anonymous_type_bcc624109a126950_0#buffer.[0] = 0; |
| 91 | |
| 92 | state->buffercxx . . $ $anonymous_type_bcc624109a126950_0#buffer.[55] = j; |
| 93 | |
| 94 | k = 1; |
| 95 | for (i = 1; i < 55; i++) |
| 96 | { |
| 97 | int n = (21 * i) % 55; |
| 98 | state->buffercxx . . $ $anonymous_type_bcc624109a126950_0#buffer.[n] = k; |
| 99 | k = j - k; |
| 100 | if (k < 0) |
| 101 | k += M_BIGcxx . . $ `external/gsl/gsl_rng__ran3.c:32:9`!; |
| 102 | j = state->buffercxx . . $ $anonymous_type_bcc624109a126950_0#buffer.[n]; |
| 103 | |
| 104 | } |
| 105 | |
| 106 | for (i1 = 0; i1 < 4; i1++) |
| 107 | { |
| 108 | for (i = 1; i < 56; i++) |
| 109 | { |
| 110 | long int t = state->buffercxx . . $ $anonymous_type_bcc624109a126950_0#buffer.[i] - state->buffercxx . . $ $anonymous_type_bcc624109a126950_0#buffer.[1 + (i + 30) % 55]; |
| 111 | if (t < 0) |
| 112 | t += M_BIGcxx . . $ `external/gsl/gsl_rng__ran3.c:32:9`!; |
| 113 | state->buffercxx . . $ $anonymous_type_bcc624109a126950_0#buffer.[i] = t; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | state->xcxx . . $ $anonymous_type_bcc624109a126950_0#x. = 0; |
| 118 | state->ycxx . . $ $anonymous_type_bcc624109a126950_0#y. = 31; |
| 119 | |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | static const gsl_rng_typecxx . . $ gsl_rng_type# ran3_typecxx . . $ ran3_type. = |
| 124 | {"ran3", /* name */ |
| 125 | M_BIGcxx . . $ `external/gsl/gsl_rng__ran3.c:32:9`!, /* RAND_MAX */ |
| 126 | 0, /* RAND_MIN */ |
| 127 | sizeof (ran3_state_tcxx . . $ ran3_state_t#), |
| 128 | &ran3_setcxx . . $ ran3_set(5500c4293b1bbef0)., |
| 129 | &ran3_getcxx . . $ ran3_get(751e5d26f8574c32)., |
| 130 | &ran3_get_doublecxx . . $ ran3_get_double(a405b17f82753acc).}; |
| 131 | |
| 132 | const gsl_rng_typecxx . . $ gsl_rng_type# *gsl_rng_ran3cxx . . $ gsl_rng_ran3. = &ran3_typecxx . . $ ran3_type.; |