00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #ifndef rng_h
00061 #define rng_h
00062 #ifndef __GSL_TYPES_H__
00063 #define __GSL_TYPES_H__
00064
00065 #ifndef GSL_VAR
00066
00067 #ifdef WIN32
00068 # ifdef _DLL
00069 # ifdef DLL_EXPORT
00070 # define GSL_VAR __declspec(dllexport)
00071 # else
00072 # define GSL_VAR __declspec(dllimport)
00073 # endif
00074 # else
00075 # define GSL_VAR extern
00076 # endif
00077 #else
00078 # define GSL_VAR extern
00079 #endif
00080
00081 #endif
00082
00083 #endif
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 #ifndef __GSL_RNG_H__
00108 #define __GSL_RNG_H__
00109 #include <cstdlib>
00110
00111 #undef __BEGIN_DECLS
00112 #undef __END_DECLS
00113 #ifdef __cplusplus
00114 # define __BEGIN_DECLS extern "C" {
00115 # define __END_DECLS }
00116 #else
00117 # define __BEGIN_DECLS
00118 # define __END_DECLS
00119 #endif
00120
00121 __BEGIN_DECLS
00122
00123 typedef struct
00124 {
00125 const char *name;
00126 unsigned long int max;
00127 unsigned long int min;
00128 size_t size;
00129 void (*set) (void *state, unsigned long int seed);
00130 unsigned long int (*get) (void *state);
00131 double (*get_double) (void *state);
00132 }
00133 gsl_rng_type;
00134
00135 typedef struct
00136 {
00137 const gsl_rng_type * type;
00138 void *state;
00139 }
00140 gsl_rng;
00141
00142
00143
00144
00145
00146 GSL_VAR const gsl_rng_type *gsl_rng_borosh13;
00147 GSL_VAR const gsl_rng_type *gsl_rng_coveyou;
00148 GSL_VAR const gsl_rng_type *gsl_rng_cmrg;
00149 GSL_VAR const gsl_rng_type *gsl_rng_fishman18;
00150 GSL_VAR const gsl_rng_type *gsl_rng_fishman20;
00151 GSL_VAR const gsl_rng_type *gsl_rng_fishman2x;
00152 GSL_VAR const gsl_rng_type *gsl_rng_gfsr4;
00153 GSL_VAR const gsl_rng_type *gsl_rng_knuthran;
00154 GSL_VAR const gsl_rng_type *gsl_rng_knuthran2;
00155 GSL_VAR const gsl_rng_type *gsl_rng_lecuyer21;
00156 GSL_VAR const gsl_rng_type *gsl_rng_minstd;
00157 GSL_VAR const gsl_rng_type *gsl_rng_mrg;
00158 GSL_VAR const gsl_rng_type *gsl_rng_mt19937;
00159 GSL_VAR const gsl_rng_type *gsl_rng_mt19937_1999;
00160 GSL_VAR const gsl_rng_type *gsl_rng_mt19937_1998;
00161 GSL_VAR const gsl_rng_type *gsl_rng_r250;
00162 GSL_VAR const gsl_rng_type *gsl_rng_ran0;
00163 GSL_VAR const gsl_rng_type *gsl_rng_ran1;
00164 GSL_VAR const gsl_rng_type *gsl_rng_ran2;
00165 GSL_VAR const gsl_rng_type *gsl_rng_ran3;
00166 GSL_VAR const gsl_rng_type *gsl_rng_rand;
00167 GSL_VAR const gsl_rng_type *gsl_rng_rand48;
00168 GSL_VAR const gsl_rng_type *gsl_rng_random128_bsd;
00169 GSL_VAR const gsl_rng_type *gsl_rng_random128_glibc2;
00170 GSL_VAR const gsl_rng_type *gsl_rng_random128_libc5;
00171 GSL_VAR const gsl_rng_type *gsl_rng_random256_bsd;
00172 GSL_VAR const gsl_rng_type *gsl_rng_random256_glibc2;
00173 GSL_VAR const gsl_rng_type *gsl_rng_random256_libc5;
00174 GSL_VAR const gsl_rng_type *gsl_rng_random32_bsd;
00175 GSL_VAR const gsl_rng_type *gsl_rng_random32_glibc2;
00176 GSL_VAR const gsl_rng_type *gsl_rng_random32_libc5;
00177 GSL_VAR const gsl_rng_type *gsl_rng_random64_bsd;
00178 GSL_VAR const gsl_rng_type *gsl_rng_random64_glibc2;
00179 GSL_VAR const gsl_rng_type *gsl_rng_random64_libc5;
00180 GSL_VAR const gsl_rng_type *gsl_rng_random8_bsd;
00181 GSL_VAR const gsl_rng_type *gsl_rng_random8_glibc2;
00182 GSL_VAR const gsl_rng_type *gsl_rng_random8_libc5;
00183 GSL_VAR const gsl_rng_type *gsl_rng_random_bsd;
00184 GSL_VAR const gsl_rng_type *gsl_rng_random_glibc2;
00185 GSL_VAR const gsl_rng_type *gsl_rng_random_libc5;
00186 GSL_VAR const gsl_rng_type *gsl_rng_randu;
00187 GSL_VAR const gsl_rng_type *gsl_rng_ranf;
00188 GSL_VAR const gsl_rng_type *gsl_rng_ranlux;
00189 GSL_VAR const gsl_rng_type *gsl_rng_ranlux389;
00190 GSL_VAR const gsl_rng_type *gsl_rng_ranlxd1;
00191 GSL_VAR const gsl_rng_type *gsl_rng_ranlxd2;
00192 GSL_VAR const gsl_rng_type *gsl_rng_ranlxs0;
00193 GSL_VAR const gsl_rng_type *gsl_rng_ranlxs1;
00194 GSL_VAR const gsl_rng_type *gsl_rng_ranlxs2;
00195 GSL_VAR const gsl_rng_type *gsl_rng_ranmar;
00196 GSL_VAR const gsl_rng_type *gsl_rng_slatec;
00197 GSL_VAR const gsl_rng_type *gsl_rng_taus;
00198 GSL_VAR const gsl_rng_type *gsl_rng_taus2;
00199 GSL_VAR const gsl_rng_type *gsl_rng_taus113;
00200 GSL_VAR const gsl_rng_type *gsl_rng_transputer;
00201 GSL_VAR const gsl_rng_type *gsl_rng_tt800;
00202 GSL_VAR const gsl_rng_type *gsl_rng_uni;
00203 GSL_VAR const gsl_rng_type *gsl_rng_uni32;
00204 GSL_VAR const gsl_rng_type *gsl_rng_vax;
00205 GSL_VAR const gsl_rng_type *gsl_rng_waterman14;
00206 GSL_VAR const gsl_rng_type *gsl_rng_zuf;
00207
00208 const gsl_rng_type ** gsl_rng_types_setup(void);
00209
00210 GSL_VAR const gsl_rng_type *gsl_rng_default;
00211 GSL_VAR unsigned long int gsl_rng_default_seed;
00212
00213 gsl_rng *gsl_rng_alloc (const gsl_rng_type * T);
00214 int gsl_rng_memcpy (gsl_rng * dest, const gsl_rng * src);
00215 gsl_rng *gsl_rng_clone (const gsl_rng * r);
00216
00217 void gsl_rng_free (gsl_rng * r);
00218
00219 void gsl_rng_set (const gsl_rng * r, unsigned long int seed);
00220 unsigned long int gsl_rng_max (const gsl_rng * r);
00221 unsigned long int gsl_rng_min (const gsl_rng * r);
00222 const char *gsl_rng_name (const gsl_rng * r);
00223 size_t gsl_rng_size (const gsl_rng * r);
00224 void * gsl_rng_state (const gsl_rng * r);
00225
00226 void gsl_rng_print_state (const gsl_rng * r);
00227
00228 const gsl_rng_type * gsl_rng_env_setup (void);
00229
00230 unsigned long int gsl_rng_get (const gsl_rng * r);
00231 double gsl_rng_uniform (const gsl_rng * r);
00232 double gsl_rng_uniform_pos (const gsl_rng * r);
00233 unsigned long int gsl_rng_uniform_int (const gsl_rng * r, unsigned long int n);
00234
00235
00236 #ifdef HAVE_INLINE
00237 extern inline unsigned long int gsl_rng_get (const gsl_rng * r);
00238
00239 extern inline unsigned long int
00240 gsl_rng_get (const gsl_rng * r)
00241 {
00242 return (r->type->get) (r->state);
00243 }
00244
00245 extern inline double gsl_rng_uniform (const gsl_rng * r);
00246
00247 extern inline double
00248 gsl_rng_uniform (const gsl_rng * r)
00249 {
00250 return (r->type->get_double) (r->state);
00251 }
00252
00253 extern inline double gsl_rng_uniform_pos (const gsl_rng * r);
00254
00255 extern inline double
00256 gsl_rng_uniform_pos (const gsl_rng * r)
00257 {
00258 double x ;
00259 do
00260 {
00261 x = (r->type->get_double) (r->state) ;
00262 }
00263 while (x == 0) ;
00264
00265 return x ;
00266 }
00267
00268 extern inline unsigned long int gsl_rng_uniform_int (const gsl_rng * r, unsigned long int n);
00269
00270 extern inline unsigned long int
00271 gsl_rng_uniform_int (const gsl_rng * r, unsigned long int n)
00272 {
00273 unsigned long int offset = r->type->min;
00274 unsigned long int range = r->type->max - offset;
00275 unsigned long int scale = range / n;
00276 unsigned long int k;
00277
00278 if (n > range)
00279 {
00280 GSL_ERROR_VAL ("n exceeds maximum value of generator",
00281 GSL_EINVAL, 0) ;
00282 }
00283
00284 do
00285 {
00286 k = (((r->type->get) (r->state)) - offset) / scale;
00287 }
00288 while (k >= n);
00289
00290 return k;
00291 }
00292 #endif
00293
00294 __END_DECLS
00295
00296 #endif
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 #ifndef __GSL_ERRNO_H__
00318 #define __GSL_ERRNO_H__
00319
00320 #include <cstdio>
00321 #include <cerrno>
00322
00323 #undef __BEGIN_DECLS
00324 #undef __END_DECLS
00325 #ifdef __cplusplus
00326 # define __BEGIN_DECLS extern "C" {
00327 # define __END_DECLS }
00328 #else
00329 # define __BEGIN_DECLS
00330 # define __END_DECLS
00331 #endif
00332
00333 __BEGIN_DECLS
00334
00335 enum {
00336 GSL_SUCCESS = 0,
00337 GSL_FAILURE = -1,
00338 GSL_CONTINUE = -2,
00339 GSL_EDOM = 1,
00340 GSL_ERANGE = 2,
00341 GSL_EFAULT = 3,
00342 GSL_EINVAL = 4,
00343 GSL_EFAILED = 5,
00344 GSL_EFACTOR = 6,
00345 GSL_ESANITY = 7,
00346 GSL_ENOMEM = 8,
00347 GSL_EBADFUNC = 9,
00348 GSL_ERUNAWAY = 10,
00349 GSL_EMAXITER = 11,
00350 GSL_EZERODIV = 12,
00351 GSL_EBADTOL = 13,
00352 GSL_ETOL = 14,
00353 GSL_EUNDRFLW = 15,
00354 GSL_EOVRFLW = 16,
00355 GSL_ELOSS = 17,
00356 GSL_EROUND = 18,
00357 GSL_EBADLEN = 19,
00358 GSL_ENOTSQR = 20,
00359 GSL_ESING = 21,
00360 GSL_EDIVERGE = 22,
00361 GSL_EUNSUP = 23,
00362 GSL_EUNIMPL = 24,
00363 GSL_ECACHE = 25,
00364 GSL_ETABLE = 26,
00365 GSL_ENOPROG = 27,
00366 GSL_ENOPROGJ = 28,
00367 GSL_ETOLF = 29,
00368 GSL_ETOLX = 30,
00369 GSL_ETOLG = 31,
00370 GSL_EOF = 32
00371 } ;
00372
00373 void gsl_error (const char * reason, const char * file, int line,
00374 int gsl_errno);
00375
00376 void gsl_warning (const char * reason, const char * file, int line,
00377 int gsl_errno) ;
00378
00379 void gsl_stream_printf (const char *label, const char *file,
00380 int line, const char *reason);
00381
00382 const char * gsl_strerror (const int gsl_errno);
00383
00384 typedef void gsl_error_handler_t (const char * reason, const char * file,
00385 int line, int gsl_errno);
00386
00387 typedef void gsl_stream_handler_t (const char * label, const char * file,
00388 int line, const char * reason);
00389
00390 gsl_error_handler_t *
00391 gsl_set_error_handler (gsl_error_handler_t * new_handler);
00392
00393 gsl_error_handler_t *
00394 gsl_set_error_handler_off (void);
00395
00396 gsl_stream_handler_t *
00397 gsl_set_stream_handler (gsl_stream_handler_t * new_handler);
00398
00399 FILE * gsl_set_stream (FILE * new_stream);
00400
00401
00402
00403 #define GSL_ERROR(reason, gsl_errno) \
00404 do { \
00405 gsl_error (reason, __FILE__, __LINE__, gsl_errno) ; \
00406 return gsl_errno ; \
00407 } while (0)
00408
00409
00410
00411 #define GSL_ERROR_VAL(reason, gsl_errno, value) \
00412 do { \
00413 gsl_error (reason, __FILE__, __LINE__, gsl_errno) ; \
00414 return value ; \
00415 } while (0)
00416
00417
00418
00419
00420 #define GSL_ERROR_VOID(reason, gsl_errno) \
00421 do { \
00422 gsl_error (reason, __FILE__, __LINE__, gsl_errno) ; \
00423 return ; \
00424 } while (0)
00425
00426
00427
00428 #define GSL_ERROR_NULL(reason, gsl_errno) GSL_ERROR_VAL(reason, gsl_errno, 0)
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440 #ifdef GSL_WARNINGS_OFF
00441 #define GSL_WARNING(warning, gsl_errno) \
00442 do { } while(0)
00443 #else
00444 #define GSL_WARNING(warning, gsl_errno) \
00445 do { \
00446 gsl_warning (warning, __FILE__, __LINE__, gsl_errno) ; \
00447 } while (0)
00448 #endif
00449
00450
00451
00452
00453 GSL_VAR int gsl_warnings_off ;
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470 #define GSL_ERROR_SELECT_2(a,b) ((a) != GSL_SUCCESS ? (a) : ((b) != GSL_SUCCESS ? (b) : GSL_SUCCESS))
00471 #define GSL_ERROR_SELECT_3(a,b,c) ((a) != GSL_SUCCESS ? (a) : GSL_ERROR_SELECT_2(b,c))
00472 #define GSL_ERROR_SELECT_4(a,b,c,d) ((a) != GSL_SUCCESS ? (a) : GSL_ERROR_SELECT_3(b,c,d))
00473 #define GSL_ERROR_SELECT_5(a,b,c,d,e) ((a) != GSL_SUCCESS ? (a) : GSL_ERROR_SELECT_4(b,c,d,e))
00474
00475 #define GSL_STATUS_UPDATE(sp, s) do { if ((s) != GSL_SUCCESS) *(sp) = (s);} while(0)
00476
00477 __END_DECLS
00478
00479 #endif
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500 #ifndef __GSL_MESSAGE_H__
00501 #define __GSL_MESSAGE_H__
00502
00503 #undef __BEGIN_DECLS
00504 #undef __END_DECLS
00505 #ifdef __cplusplus
00506 # define __BEGIN_DECLS extern "C" {
00507 # define __END_DECLS }
00508 #else
00509 # define __BEGIN_DECLS
00510 # define __END_DECLS
00511 #endif
00512
00513 __BEGIN_DECLS
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523 void gsl_message(const char * message, const char * file, int line,
00524 unsigned int mask);
00525
00526 #ifndef GSL_MESSAGE_MASK
00527 #define GSL_MESSAGE_MASK 0xffffffffu
00528 #endif
00529
00530 GSL_VAR unsigned int gsl_message_mask ;
00531
00532
00533
00534 enum {
00535 GSL_MESSAGE_MASK_A = 1,
00536 GSL_MESSAGE_MASK_B = 2,
00537 GSL_MESSAGE_MASK_C = 4,
00538 GSL_MESSAGE_MASK_D = 8,
00539 GSL_MESSAGE_MASK_E = 16,
00540 GSL_MESSAGE_MASK_F = 32,
00541 GSL_MESSAGE_MASK_G = 64,
00542 GSL_MESSAGE_MASK_H = 128
00543 } ;
00544
00545 #ifdef GSL_MESSAGING_OFF
00546 #define GSL_MESSAGE(message, mask) do { } while(0)
00547 #else
00548 #define GSL_MESSAGE(message, mask) \
00549 do { \
00550 if (mask & GSL_MESSAGE_MASK) \
00551 gsl_message (message, __FILE__, __LINE__, mask) ; \
00552 } while (0)
00553 #endif
00554
00555 __END_DECLS
00556
00557 #endif
00558
00560
00561
00562
00563
00564
00565 #include <ctime>
00566
00567 class Rng {
00568
00569 gsl_rng * r;
00570
00571 unsigned long int seed_no;
00572
00573
00574 public:
00575
00576 Rng();
00577
00578 ~Rng();
00579
00580
00581
00582 void seed(unsigned long int n);
00583
00584 double draw();
00585
00586 unsigned long int showseed();
00587 };
00588
00589 #endif