forked from ecell/epdp
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathGSLRandomNumberGenerator.hpp
62 lines (48 loc) · 1.28 KB
/
GSLRandomNumberGenerator.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef GSLRANDOMNUMBERGENERATOR_HPP
#define GSLRANDOMNUMBERGENERATOR_HPP
#include <boost/shared_ptr.hpp>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
class GSLRandomNumberGenerator
{
public:
typedef boost::shared_ptr<gsl_rng> rng_handle;
double normal(double loc, double scale)
{
return gsl_ran_gaussian(rng_.get(), scale) + loc;
}
unsigned long int get_raw()
{
return gsl_rng_get(rng_.get());
}
double uniform(double min, double max)
{
return gsl_rng_uniform(rng_.get()) * (max - min) + min;
}
int uniform_int(int min, int max)
{
return gsl_rng_uniform_int(rng_.get(), max - min + 1) + min;
}
void dir_2d(double *x, double *y)
{
gsl_ran_dir_2d(rng_.get(), x, y);
}
void dir_3d(double *x, double *y, double *z)
{
gsl_ran_dir_3d(rng_.get(), x, y, z);
}
double operator()()
{
return gsl_rng_uniform(rng_.get());
}
void seed(unsigned long int val)
{
gsl_rng_set(rng_.get(), val);
}
GSLRandomNumberGenerator(rng_handle hdl): rng_(hdl)
{
}
GSLRandomNumberGenerator(gsl_rng* rng = gsl_rng_alloc(gsl_rng_mt19937)): rng_(rng, &gsl_rng_free) {}
rng_handle rng_;
};
#endif /* GSLRANDOMNUMBERGENERATOR_HPP */