20 #ifndef __FASTJET_BASICRANDOM_HH__
21 #define __FASTJET_BASICRANDOM_HH__ 1
27 #include "fastjet/internal/base.hh"
29 FASTJET_BEGIN_NAMESPACE
36 template<
typename _Tp>
class BasicRandom {
38 typedef _Tp value_type;
39 typedef unsigned int size_type;
40 typedef value_type* pointer;
43 value_type operator() ();
44 void operator() (size_type, pointer);
47 void randomize(
void *);
50 static value_type min();
51 static value_type max();
54 void print_info(std::ostream& __os = std::cout);
58 int __default_random_generator(
int *__iseed);
68 class BasicRandom<int>
71 typedef int value_type;
72 typedef unsigned int size_type;
73 typedef value_type* pointer;
76 explicit BasicRandom(
int __s1 = 12345,
int __s2 = 67890) {
82 value_type operator() () {
83 return __default_random_generator(_M_iseed);
86 void operator() (size_type __n, pointer __res) {
87 for(size_type __i = 0; __i < __n; __i++)
88 __res[__i] = __default_random_generator(_M_iseed);
92 void randomize(
void *__iseed) {
93 int *__new_seed = (
int*) __iseed;
94 _M_iseed[0] = __new_seed[0];
95 _M_iseed[1] = __new_seed[1];
98 void set_status(
const std::vector<int> & __iseed) {
99 assert(__iseed.size() >= 2);
100 _M_iseed[0] = __iseed[0];
101 _M_iseed[1] = __iseed[1];
104 void get_status(std::vector<int> & __iseed) {
106 __iseed[0] = _M_iseed[0];
107 __iseed[1] = _M_iseed[1];
111 inline static value_type min() {
return 0;}
112 inline static value_type max() {
return 2147483647;}
115 void print_info(std::ostream& __os = std::cout) {
116 __os<<
"BasicRandom<int> : "<<_M_iseed[0]<<
", "<<_M_iseed[1]<<std::endl;
128 template<>
class BasicRandom<double> {
130 typedef double value_type;
131 typedef unsigned int size_type;
132 typedef value_type* pointer;
135 explicit BasicRandom(
int __s1 = 12345,
int __s2 = 67890) {
142 value_type operator() () {
143 return 4.6566128752457969241e-10*__default_random_generator(_M_iseed);
148 void operator() (size_type __n, pointer __res) {
149 for(size_type __i = 0; __i < __n; __i++)
150 __res[__i] =
this ->
operator()();
154 void randomize(
void *__iseed) {
155 int *__new_seed = (
int*) __iseed;
156 _M_iseed[0] = __new_seed[0];
157 _M_iseed[1] = __new_seed[1];
160 void set_status(
const std::vector<int> & __iseed) {
161 assert(__iseed.size() >= 2);
162 _M_iseed[0] = __iseed[0];
163 _M_iseed[1] = __iseed[1];
166 void get_status(std::vector<int> & __iseed) {
168 __iseed[0] = _M_iseed[0];
169 __iseed[1] = _M_iseed[1];
173 inline static value_type min() {
return 0.0;}
175 inline static value_type max() {
return 1.0;}
178 void print_info(std::ostream& __os = std::cout) {
179 __os<<
"BasicRandom<double> : "<<_M_iseed[0]<<
", "<<_M_iseed[1]<<std::endl;
187 extern BasicRandom<int> _G_random_int;
188 extern BasicRandom<double> _G_random_double;
191 FASTJET_END_NAMESPACE
193 #endif // __FASTJET_BASICRANDOM_HH__