00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <stdlib.h>
00029 #include <math.h>
00030
00031 #include <gsl/gsl_rng.h>
00032 #include <gsl/gsl_randist.h>
00033
00034 #ifndef ___RNDGEN_H___
00035 #define ___RNDGEN_H___
00036
00041
00056
00057
00062 void SetSeed(char* genType,
00063 int seed);
00064
00066
00067
00069
00076 double rndUniformDouble(double low=0.0, double high=1.0);
00077
00079
00086 long int rndUniformInt(long int low=0, long int high=1);
00087
00089
00095 double rndExponential(double M);
00096
00098
00105 double rndGaussian(double M, double sigma);
00106
00108
00114 unsigned int rndGeometric0(double M);
00115
00117
00123 unsigned int rndGeometric1(double M);
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00138
00153 long int rndNegativeBinomial(long r, float p);
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00167
00182 double rndPareto(double location, double shape);
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00197
00213 double rndWeibull(double location, double scale, double shape);
00214
00216
00230 double rndRayleigh(double sigma);
00231
00233
00240 void rndShuffle( void* vect, size_t size, size_t elem_size );
00241
00242
00244
00248 class UniformDoubleRndGen
00249 {
00250 protected:
00251 double low, high;
00252 double range;
00253
00254 public:
00255 UniformDoubleRndGen(double _low=0,
00256 double _high=1)
00257 : low(_low), high(_high), range(_high-_low) {};
00258
00260 double get();
00261 };
00262
00264
00268 class UniformIntRndGen
00269 {
00270 protected:
00271 long int low, high;
00272 long int range;
00273 public:
00274 UniformIntRndGen(long int _low=0,
00275 long int _high=1)
00276 : low(_low), high(_high), range(_high-_low+1) {};
00277
00279 long int get();
00280 };
00281
00283
00287 class ExponentialRndGen
00288 {
00289 protected:
00290 double meanExp;
00291
00292 public:
00293 ExponentialRndGen(double _mean=0)
00294 : meanExp(_mean) {};
00295
00297 double get();
00298 };
00299
00301
00305 class GaussianRndGen
00306 {
00307 protected:
00308 double mean, sigma;
00309
00310 public:
00311 GaussianRndGen(double _mean=0,
00312 double _sigma=0)
00313 : mean(_mean), sigma(_sigma) {};
00314
00316 double get();
00317 };
00318
00320
00324 class Geometric0RndGen
00325 {
00326 protected:
00327 double meanGeo0;
00328 double pGeo0;
00329
00330 public:
00331 Geometric0RndGen(double _mean=0)
00332 : meanGeo0(_mean)
00333 {
00334 if( _mean > 0 )
00335 pGeo0 = 1 / (_mean + 1);
00336 };
00337
00338
00340 unsigned long int get();
00341 };
00342
00344
00348 class Geometric1RndGen
00349 {
00350 protected:
00351 double meanGeo1;
00352 double pGeo1;
00353
00354 public:
00355 Geometric1RndGen(double _mean=1)
00356 : meanGeo1(_mean)
00357 {
00358 if( _mean > 1 )
00359 pGeo1 = 1 / _mean;
00360 };
00361
00363 unsigned long int get();
00364 };
00365
00367
00379 class ParetoRndGen
00380 {
00381 protected:
00382 double location;
00383 double shape;
00384
00385 public:
00386 ParetoRndGen(double _location=1,
00387 double _shape=1)
00388 : location(_location), shape(_shape)
00389 {};
00390
00392 double get();
00393 };
00394
00396
00408 class WeibullRndGen
00409 {
00410 protected:
00411 double location;
00412 double scale;
00413 double shape;
00414
00415 public:
00416 WeibullRndGen(double _location=1,
00417 double _scale=1,
00418 double _shape=1)
00419 : location(_location), scale(_scale), shape(_shape)
00420 {};
00421
00423 double get();
00424 };
00425
00427
00439 class RayleighRndGen
00440 {
00441 protected:
00442 double sigma;
00443
00444 public:
00445 RayleighRndGen(double _sigma=1)
00446 : sigma(_sigma)
00447 {};
00448
00450 double get();
00451 };
00452
00454
00455 #endif
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506