EMAN2
|
The wrapper class for gsl's random number generater. More...
#include <randnum.h>
Public Member Functions | |
void | set_seed (unsigned long long seed) |
Set the seed for the random number generator. More... | |
unsigned long long | get_seed () |
Get the current random number seed. More... | |
long long | get_irand (long long lo, long long hi) const |
This function returns a random integer from lo to hi inclusive. More... | |
float | get_frand (double lo=0.0, double hi=1.0) const |
This function returns a random float from lo inclusive to hi. More... | |
float | get_frand_pos (double lo=0.0, double hi=1.0) const |
This function returns a random float from lo to hi. More... | |
float | get_gauss_rand (float mean, float sigma) const |
Return a Gaussian random number. More... | |
void | print_generator_type () const |
print out all possible random number generator type in gsl More... | |
Static Public Member Functions | |
static Randnum * | Instance () |
static Randnum * | Instance (const gsl_rng_type *_t) |
Protected Member Functions | |
Randnum () | |
The default constructor will use the gsl default random number generator gal_rng_mt19937. More... | |
Randnum (const Randnum &) | |
Randnum (const gsl_rng_type *_t) | |
This constructor is for setting the new random number generator engine other than gsl default gsl_rng_mt19937. More... | |
~Randnum () | |
Static Private Attributes | |
static const gsl_rng_type * | T = gsl_rng_default |
static gsl_rng * | r = 0 |
static unsigned long long | _seed = random_seed() |
static Randnum * | _instance = 0 |
The wrapper class for gsl's random number generater.
This class is a singleton class. the default random number generator engine is gsl default: gsl_rng_mt19937, gsl_rng_mt19937 has a period 2^19937. the default seed is from /dev/random or milli second of current time.
- How to get a random integer in range [lo, hi]
|
protected |
The default constructor will use the gsl default random number generator gal_rng_mt19937.
This is a very good choice which has a period of 2^19937 and not sacrifice performance too much.
Definition at line 125 of file randnum.cpp.
Referenced by Instance().
|
protected |
|
explicitprotected |
This constructor is for setting the new random number generator engine other than gsl default gsl_rng_mt19937.
For example: gsl_rng_rand is the gsl version of rand() function, which is 100% faster than the rand() function in C.
_t | the random number generator type |
Definition at line 131 of file randnum.cpp.
|
protected |
float Randnum::get_frand | ( | double | lo = 0.0 , |
double | hi = 1.0 |
||
) | const |
This function returns a random float from lo inclusive to hi.
lo | the low end of the random float |
hi | the high end of the random float |
Definition at line 158 of file randnum.cpp.
References r.
Referenced by EMAN::Util::get_frand(), EMAN::AddRandomNoiseProcessor::process_inplace(), and EMAN::TestImageNoiseUniformRand::process_inplace().
float Randnum::get_frand_pos | ( | double | lo = 0.0 , |
double | hi = 1.0 |
||
) | const |
This function returns a random float from lo to hi.
lo | the low end of the random float |
hi | the high end of the random float |
Definition at line 163 of file randnum.cpp.
References r.
Referenced by get_gauss_rand().
float Randnum::get_gauss_rand | ( | float | mean, |
float | sigma | ||
) | const |
Return a Gaussian random number.
[in] | mean | The gaussian mean |
[in] | sigma | The gaussian sigma |
Definition at line 168 of file randnum.cpp.
References get_frand_pos(), log(), r, sqrt(), x, and y.
Referenced by EMAN::Util::get_gauss_rand(), EMAN::AddNoiseProcessor::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), and EMAN::TestImageNoiseGauss::process_inplace().
long long Randnum::get_irand | ( | long long | lo, |
long long | hi | ||
) | const |
This function returns a random integer from lo to hi inclusive.
All integers in the range [lo,hi] are produced with equal probability.
lo | the low end of the random integer |
hi | the high end of the random integer |
Definition at line 153 of file randnum.cpp.
References r.
Referenced by EMAN::Util::get_irand().
unsigned long long Randnum::get_seed | ( | ) |
Get the current random number seed.
Definition at line 148 of file randnum.cpp.
References _seed.
Referenced by EMAN::Util::get_randnum_seed().
|
static |
Definition at line 104 of file randnum.cpp.
References _instance, and Randnum().
Referenced by EMAN::Util::get_frand(), EMAN::Util::get_gauss_rand(), EMAN::Util::get_irand(), EMAN::Util::get_randnum_seed(), EMAN::AddNoiseProcessor::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), EMAN::TestImageNoiseUniformRand::process_inplace(), EMAN::TestImageNoiseGauss::process_inplace(), and EMAN::Util::set_randnum_seed().
|
static |
Definition at line 112 of file randnum.cpp.
void Randnum::print_generator_type | ( | ) | const |
print out all possible random number generator type in gsl
Definition at line 190 of file randnum.cpp.
void Randnum::set_seed | ( | unsigned long long | seed | ) |
Set the seed for the random number generator.
If the generator is seeded with the same value of s on two different runs, the same stream of random numbers will be generated by successive calls to the routines below. If different values of s are supplied, then the generated streams of random numbers should be completely different. If the seed s is zero then the standard seed from the original implementation is used instead.
seed | the seed for random number generator |
Definition at line 142 of file randnum.cpp.
Referenced by EMAN::AddNoiseProcessor::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), EMAN::TestImageNoiseUniformRand::process_inplace(), EMAN::TestImageNoiseGauss::process_inplace(), and EMAN::Util::set_randnum_seed().
|
staticprivate |
Definition at line 169 of file randnum.h.
Referenced by Instance().
|
staticprivate |
Definition at line 167 of file randnum.h.
Referenced by get_seed(), Instance(), Randnum(), and set_seed().
|
staticprivate |
Definition at line 166 of file randnum.h.
Referenced by get_frand(), get_frand_pos(), get_gauss_rand(), get_irand(), Instance(), Randnum(), set_seed(), and ~Randnum().
|
staticprivate |
Definition at line 165 of file randnum.h.
Referenced by Instance(), and Randnum().