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 * This implementation copyright (C) 2001 Carlo Perassi
29 * and (C) 2003 Heiko Bauke.
30 * Carlo Perassi reorganized the code to use the rng framework of GSL.
35 #include <gsl/gsl_rng.h>
37 #define MM 0xffffffffUL /* 2 ^ 32 - 1 */
39 static inline unsigned long int ran_get (void *vstate);
40 static double ran_get_double (void *vstate);
41 static void ran_set (void *state, unsigned long int s);
49 static inline unsigned long int
50 ran_get (void *vstate)
52 ran_state_t *state = (ran_state_t *) vstate;
54 state->x = (state->x * (state->x + 1)) & MM;
60 ran_get_double (void *vstate)
62 ran_state_t *state = (ran_state_t *) vstate;
64 return ran_get (state) / 4294967296.0;
68 ran_set (void *vstate, unsigned long int s)
70 ran_state_t *state = (ran_state_t *) vstate;
72 unsigned long int diff = ((s % 4UL) - 2UL) % MM;
75 state->x = (s - diff) & MM;
82 static const gsl_rng_type ran_type = {
92 const gsl_rng_type *gsl_rng_coveyou = &ran_type;