3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2004, 2007 James Theiler, Brian Gough
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.
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.
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.
23 #include <gsl/gsl_types.h>
24 #include <gsl/gsl_errno.h>
29 # define __BEGIN_DECLS extern "C" {
30 # define __END_DECLS }
32 # define __BEGIN_DECLS /* empty */
33 # define __END_DECLS /* empty */
41 unsigned long int max;
42 unsigned long int min;
44 void (*set) (void *state, unsigned long int seed);
45 unsigned long int (*get) (void *state);
46 double (*get_double) (void *state);
52 const gsl_rng_type * type;
58 /* These structs also need to appear in default.c so you can select
59 them via the environment variable GSL_RNG_TYPE */
61 GSL_VAR const gsl_rng_type *gsl_rng_borosh13;
62 GSL_VAR const gsl_rng_type *gsl_rng_coveyou;
63 GSL_VAR const gsl_rng_type *gsl_rng_cmrg;
64 GSL_VAR const gsl_rng_type *gsl_rng_fishman18;
65 GSL_VAR const gsl_rng_type *gsl_rng_fishman20;
66 GSL_VAR const gsl_rng_type *gsl_rng_fishman2x;
67 GSL_VAR const gsl_rng_type *gsl_rng_gfsr4;
68 GSL_VAR const gsl_rng_type *gsl_rng_knuthran;
69 GSL_VAR const gsl_rng_type *gsl_rng_knuthran2;
70 GSL_VAR const gsl_rng_type *gsl_rng_knuthran2002;
71 GSL_VAR const gsl_rng_type *gsl_rng_lecuyer21;
72 GSL_VAR const gsl_rng_type *gsl_rng_minstd;
73 GSL_VAR const gsl_rng_type *gsl_rng_mrg;
74 GSL_VAR const gsl_rng_type *gsl_rng_mt19937;
75 GSL_VAR const gsl_rng_type *gsl_rng_mt19937_1999;
76 GSL_VAR const gsl_rng_type *gsl_rng_mt19937_1998;
77 GSL_VAR const gsl_rng_type *gsl_rng_r250;
78 GSL_VAR const gsl_rng_type *gsl_rng_ran0;
79 GSL_VAR const gsl_rng_type *gsl_rng_ran1;
80 GSL_VAR const gsl_rng_type *gsl_rng_ran2;
81 GSL_VAR const gsl_rng_type *gsl_rng_ran3;
82 GSL_VAR const gsl_rng_type *gsl_rng_rand;
83 GSL_VAR const gsl_rng_type *gsl_rng_rand48;
84 GSL_VAR const gsl_rng_type *gsl_rng_random128_bsd;
85 GSL_VAR const gsl_rng_type *gsl_rng_random128_glibc2;
86 GSL_VAR const gsl_rng_type *gsl_rng_random128_libc5;
87 GSL_VAR const gsl_rng_type *gsl_rng_random256_bsd;
88 GSL_VAR const gsl_rng_type *gsl_rng_random256_glibc2;
89 GSL_VAR const gsl_rng_type *gsl_rng_random256_libc5;
90 GSL_VAR const gsl_rng_type *gsl_rng_random32_bsd;
91 GSL_VAR const gsl_rng_type *gsl_rng_random32_glibc2;
92 GSL_VAR const gsl_rng_type *gsl_rng_random32_libc5;
93 GSL_VAR const gsl_rng_type *gsl_rng_random64_bsd;
94 GSL_VAR const gsl_rng_type *gsl_rng_random64_glibc2;
95 GSL_VAR const gsl_rng_type *gsl_rng_random64_libc5;
96 GSL_VAR const gsl_rng_type *gsl_rng_random8_bsd;
97 GSL_VAR const gsl_rng_type *gsl_rng_random8_glibc2;
98 GSL_VAR const gsl_rng_type *gsl_rng_random8_libc5;
99 GSL_VAR const gsl_rng_type *gsl_rng_random_bsd;
100 GSL_VAR const gsl_rng_type *gsl_rng_random_glibc2;
101 GSL_VAR const gsl_rng_type *gsl_rng_random_libc5;
102 GSL_VAR const gsl_rng_type *gsl_rng_randu;
103 GSL_VAR const gsl_rng_type *gsl_rng_ranf;
104 GSL_VAR const gsl_rng_type *gsl_rng_ranlux;
105 GSL_VAR const gsl_rng_type *gsl_rng_ranlux389;
106 GSL_VAR const gsl_rng_type *gsl_rng_ranlxd1;
107 GSL_VAR const gsl_rng_type *gsl_rng_ranlxd2;
108 GSL_VAR const gsl_rng_type *gsl_rng_ranlxs0;
109 GSL_VAR const gsl_rng_type *gsl_rng_ranlxs1;
110 GSL_VAR const gsl_rng_type *gsl_rng_ranlxs2;
111 GSL_VAR const gsl_rng_type *gsl_rng_ranmar;
112 GSL_VAR const gsl_rng_type *gsl_rng_slatec;
113 GSL_VAR const gsl_rng_type *gsl_rng_taus;
114 GSL_VAR const gsl_rng_type *gsl_rng_taus2;
115 GSL_VAR const gsl_rng_type *gsl_rng_taus113;
116 GSL_VAR const gsl_rng_type *gsl_rng_transputer;
117 GSL_VAR const gsl_rng_type *gsl_rng_tt800;
118 GSL_VAR const gsl_rng_type *gsl_rng_uni;
119 GSL_VAR const gsl_rng_type *gsl_rng_uni32;
120 GSL_VAR const gsl_rng_type *gsl_rng_vax;
121 GSL_VAR const gsl_rng_type *gsl_rng_waterman14;
122 GSL_VAR const gsl_rng_type *gsl_rng_zuf;
124 const gsl_rng_type ** gsl_rng_types_setup(void);
126 GSL_VAR const gsl_rng_type *gsl_rng_default;
127 GSL_VAR unsigned long int gsl_rng_default_seed;
129 gsl_rng *gsl_rng_alloc (const gsl_rng_type * T);
130 int gsl_rng_memcpy (gsl_rng * dest, const gsl_rng * src);
131 gsl_rng *gsl_rng_clone (const gsl_rng * r);
133 void gsl_rng_free (gsl_rng * r);
135 void gsl_rng_set (const gsl_rng * r, unsigned long int seed);
136 unsigned long int gsl_rng_max (const gsl_rng * r);
137 unsigned long int gsl_rng_min (const gsl_rng * r);
138 const char *gsl_rng_name (const gsl_rng * r);
140 int gsl_rng_fread (FILE * stream, gsl_rng * r);
141 int gsl_rng_fwrite (FILE * stream, const gsl_rng * r);
143 size_t gsl_rng_size (const gsl_rng * r);
144 void * gsl_rng_state (const gsl_rng * r);
146 void gsl_rng_print_state (const gsl_rng * r);
148 const gsl_rng_type * gsl_rng_env_setup (void);
150 unsigned long int gsl_rng_get (const gsl_rng * r);
151 double gsl_rng_uniform (const gsl_rng * r);
152 double gsl_rng_uniform_pos (const gsl_rng * r);
153 unsigned long int gsl_rng_uniform_int (const gsl_rng * r, unsigned long int n);
157 extern inline unsigned long int gsl_rng_get (const gsl_rng * r);
159 extern inline unsigned long int
160 gsl_rng_get (const gsl_rng * r)
162 return (r->type->get) (r->state);
165 extern inline double gsl_rng_uniform (const gsl_rng * r);
168 gsl_rng_uniform (const gsl_rng * r)
170 return (r->type->get_double) (r->state);
173 extern inline double gsl_rng_uniform_pos (const gsl_rng * r);
176 gsl_rng_uniform_pos (const gsl_rng * r)
181 x = (r->type->get_double) (r->state) ;
188 extern inline unsigned long int gsl_rng_uniform_int (const gsl_rng * r, unsigned long int n);
190 extern inline unsigned long int
191 gsl_rng_uniform_int (const gsl_rng * r, unsigned long int n)
193 unsigned long int offset = r->type->min;
194 unsigned long int range = r->type->max - offset;
195 unsigned long int scale;
198 if (n > range || n == 0)
200 GSL_ERROR_VAL ("invalid n, either 0 or exceeds maximum value of generator",
208 k = (((r->type->get) (r->state)) - offset) / scale;
214 #endif /* HAVE_INLINE */
218 #endif /* __GSL_RNG_H__ */