20 #include "randomgenerator.h"
25 #include "gsl/gsl_rng.h"
26 #include "gsl/gsl_randist.h"
36 rng = gsl_rng_alloc( gsl_rng_taus2 );
56 gsl_rng_set( prive->rng, seed );
58 srand((
unsigned int)seed);
69 gsl_rng_set( prive->rng, seed );
71 srand((
unsigned int)seed);
81 return ( gsl_rng_uniform( prive->rng ) < trueProbability );
83 return ( (
double( rand() ) /
double( RAND_MAX ) ) < trueProbability );
89 return ( gsl_rng_uniform_int( prive->rng, qAbs( max-min )+1 ) + min );
91 return ( min + ( rand() % ( max-min ) ) );
98 return gsl_ran_flat( prive->rng, min, max );
100 return ( min + (
double( rand() ) /
double( RAND_MAX ) ) * ( max - min ) );
106 return gsl_ran_gaussian( prive->rng, var ) + mean;
111 const double stdDev = sqrt(var);
112 if (prive->isSpareReady) {
113 prive->isSpareReady =
false;
114 return prive->spare * stdDev + mean;
118 u = (double(rand()) / double(RAND_MAX)) * 2.0 - 1.0;
119 v = (double(rand()) / double(RAND_MAX)) * 2.0 - 1.0;
121 }
while (s >= 1.0 || s == 0.0);
123 const double mul = sqrt(-2.0 * log(s) / s);
124 prive->spare = v * mul;
125 prive->isSpareReady =
true;
126 return mean + stdDev * u * mul;
~RandomGenerator()
Destructor.
RandomGenerator(int seed=0)
Default Constructor.
A macro to deprecate functions.
FARSA_UTIL_TEMPLATE const T max(const T &t1, const U &t2)
Template for max calculation.
void setSeed(int seed)
set the seed of this random number generator
int getInt(int min, int max)
return a random number within range specified (extreme inclusive) with a Flat distribution ...
bool getBool(double trueProbability)
return true with probability trueProbability, otherwise false
double getGaussian(double var, double mean=0.0)
return a random number accordlying to a Gaussian distribution
FARSA_UTIL_TEMPLATE const T min(const T &t1, const U &t2)
Template for min calculation.
double getDouble(double min, double max)
return a random number within range specified (extreme inclusive) with a Flat distribution ...
int seed()
Return the seed setted.