random.h 2.22 KB
Newer Older
Stefan Weßel's avatar
ic  
Stefan Weßel committed
1
2
3
4
5
6
#ifndef MCL_RANDOM_H
#define MCL_RANDOM_H

#include "dump.h"
#include "types.h"

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#define MCL_RNG_MT

#ifdef MCL_RNG_MT
#include "MersenneTwister.h"
class randomnumbergenerator
{
public:
	randomnumbergenerator();
	randomnumbergenerator(luint seed);
	~randomnumbergenerator() {delete ptr;}
	void write(odump&);
	void read(idump&);
	luint seed() {return my_seed;}
	double d() {return ptr->randDblExc();}                 //in (0,1)
	double d(double supp) {return ptr->randDblExc(supp);}  //in (0,supp)
	int i(int bound) {return ptr->randInt(bound-1);}       //in [0,bound)

24
25
	double norm(); // normal distribution, mean = 0, std = 1

26
27
28
29
30
31
32
33
private:
	MTRand* ptr; 
	luint my_seed;
};
#endif

#ifdef MCL_RNG_SPRNG_4
#include "sprng_cpp.h"
Stefan Weßel's avatar
ic  
Stefan Weßel committed
34
35
36
37
38
class randomnumbergenerator
{
public:
	randomnumbergenerator();
	randomnumbergenerator(luint seed);
39
	~randomnumbergenerator() {delete ptr;}
Stefan Weßel's avatar
ic  
Stefan Weßel committed
40
41
	void write(odump&);
	void read(idump&);
42
43
44
45
	luint seed() {return my_seed;}
	double d() {return ptr->sprng();}         //in (0,1)
	double d(double supp) {return supp*d();}  //in (0,supp)
	int i(int bound) {return int(bound*d());} //in [0,bound)
Stefan Weßel's avatar
ic  
Stefan Weßel committed
46
47

private:
48
49
50
51
	Sprng * ptr;
	luint my_seed;
};
#endif
Stefan Weßel's avatar
ic  
Stefan Weßel committed
52

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

#ifdef MCL_RNG_BOOST
#include <boost/random.hpp>
class randomnumbergenerator
{
public:
	randomnumbergenerator();
	randomnumbergenerator(int seed);
	void write(odump&);
	void read(idump&);
	luint seed() {return my_seed;}
	double d() {return (*val)(*rng);}    	  //returns a value between 0 (excl) and 1 (excl).
	double d(double supp) {return supp*d();}  //returns a value between 0 (excl) and supp (excl.)
	int i(int bound) {return int(bound*d());} //returns a value between 0 (incl) and bound (excl.)

private:
	boost::mt19937 * rng;
	boost::uniform_real<> * val;
	luint my_seed;
Stefan Weßel's avatar
ic  
Stefan Weßel committed
72
};
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#endif

// #ifdef MCL_RNG_ACML
// #warning RNG: ACML
// #include "acml_rand.h"
// class randomnumbergenerator
// {
// 	public:
// 		randomnumbergenerator(int seed);
// 		double d() {return (*gen)();}         //returns a value between 0 (excl) and 1 (excl).
// 		double d(double supp) {return supp*d();}  //returns a value between 0 (excl) and supp (excl.)
// 		int i(int bound) {return int(bound*d());} //returns a value between 0 (incl) and bound (excl.)
// 
// 	private:
// 		acml_rand * gen;
// 
// };
// 
// #endif
Stefan Weßel's avatar
ic  
Stefan Weßel committed
92
93
94
95


#endif