3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 3 of the License, or (at
6 * your option) any later version.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * This generator is taken from
22 * The Art of Computer Programming
28 * It is called "Fishman - L'Ecuyer"
30 * This implementation copyright (C) 2001 Carlo Perassi
31 * and (C) 2003 Heiko Bauke.
36 #include <gsl/gsl_rng.h>
40 #define MMM_F 0x7fffffffUL /* 2 ^ 31 - 1 */
46 #define MMM_L 0x7fffff07UL /* 2 ^ 31 - 249 */
50 static inline unsigned long int ran_get (void *vstate);
51 static double ran_get_double (void *vstate);
52 static void ran_set (void *state, unsigned long int s);
62 static inline unsigned long int
63 ran_get (void *vstate)
65 ran_state_t *state = (ran_state_t *) vstate;
69 r = RRR_F * (state->x / QQQ_F);
70 y = AAA_F * (state->x % QQQ_F) - r;
75 r = RRR_L * (state->y / QQQ_L);
76 y = AAA_L * (state->y % QQQ_L) - r;
81 state->z = (state->x > state->y) ? (state->x - state->y) :
82 MMM_F + state->x - state->y;
88 ran_get_double (void *vstate)
90 ran_state_t *state = (ran_state_t *) vstate;
92 return ran_get (state) / 2147483647.0;
96 ran_set (void *vstate, unsigned long int s)
98 ran_state_t *state = (ran_state_t *) vstate;
100 if ((s % MMM_F) == 0 || (s % MMM_L) == 0)
101 s = 1; /* default seed is 1 */
103 state->x = s % MMM_F;
104 state->y = s % MMM_L;
105 state->z = (state->x > state->y) ? (state->x - state->y) :
106 MMM_F + state->x - state->y;
111 static const gsl_rng_type ran_type = {
112 "fishman2x", /* name */
113 MMM_F - 1, /* RAND_MAX */
115 sizeof (ran_state_t),
121 const gsl_rng_type *gsl_rng_fishman2x = &ran_type;