39 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
40 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
42 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
54 unsigned long long random_seed()
60 if ((devrandom = fopen(
"/dev/urandom",
"r")) == NULL) {
62 seed = tv.tv_sec + tv.tv_usec;
66 fread(&seed,
sizeof(seed),1,devrandom);
75 unsigned long long random_seed()
78 unsigned __int64 tmpres = 0;
82 GetSystemTimeAsFileTime(&ft);
83 tmpres |= ft.dwHighDateTime;
85 tmpres |= ft.dwLowDateTime;
89 tmpres -= DELTA_EPOCH_IN_MICROSECS;
90 tv.tv_sec = (
long long)(tmpres / 1000000UL);
91 tv.tv_usec = (
long long)(tmpres % 1000000UL);
93 unsigned long long seed = tv.tv_sec + tv.tv_usec;
99Randnum * Randnum::_instance = 0;
100const gsl_rng_type * Randnum::T = gsl_rng_default;
101gsl_rng * Randnum::r = 0;
102unsigned long long Randnum::_seed = random_seed();
127 r = gsl_rng_alloc (
T);
133 r = gsl_rng_alloc (_t);
155 return gsl_rng_uniform_int(
r, hi-lo+1)+lo;
160 return static_cast<float>(gsl_rng_uniform(
r) * (hi -lo) + lo);
165 return static_cast<float>(gsl_rng_uniform_pos(
r) * (hi -lo) + lo);
180 if (r <= 1.0 && r > 0) {
186 float result =
x * f * sigma + mean;
192 const gsl_rng_type **t, **t0;
194 t0 = gsl_rng_types_setup ();
196 printf (
"Available generators:\n");
198 for (t = t0; *t != 0; t++) {
199 printf (
"%s\n", (*t)->name);
The wrapper class for gsl's random number generater.
static unsigned long long _seed
void print_generator_type() const
print out all possible random number generator type in gsl
void set_seed(unsigned long long seed)
Set the seed for the random number generator.
static const gsl_rng_type * T
static Randnum * Instance()
static Randnum * _instance
Randnum()
The default constructor will use the gsl default random number generator gal_rng_mt19937.
long long get_irand(long long lo, long long hi) const
This function returns a random integer from lo to hi inclusive.
unsigned long long get_seed()
Get the current random number seed.
float get_gauss_rand(float mean, float sigma) const
Return a Gaussian random number.
float get_frand(double lo=0.0, double hi=1.0) const
This function returns a random float from lo inclusive to hi.
float get_frand_pos(double lo=0.0, double hi=1.0) const
This function returns a random float from lo to hi.
EMData * log() const
return natural logarithm image for a image
EMData * sqrt() const
return square root of current image