27 #ifndef __FASTJET_BASICRANDOM_HH__
28 #define __FASTJET_BASICRANDOM_HH__ 1
34 #include "fastjet/internal/base.hh"
36 #include "fastjet/config.h"
37 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
42 FASTJET_BEGIN_NAMESPACE
49 template<
typename _Tp>
class BasicRandom {
51 typedef _Tp value_type;
52 typedef unsigned int size_type;
53 typedef value_type* pointer;
56 value_type operator() ();
57 void operator() (size_type, pointer);
60 void randomize(
void *);
63 static value_type min();
64 static value_type max();
67 void print_info(std::ostream& __os = std::cout);
71 int __default_random_generator(
int *__iseed);
81 class BasicRandom<int>
84 typedef int value_type;
85 typedef unsigned int size_type;
86 typedef value_type* pointer;
89 explicit BasicRandom(
int __s1 = 12345,
int __s2 = 67890) {
95 value_type operator() () {
96 return __default_random_generator(_M_iseed);
99 void operator() (size_type __n, pointer __res) {
100 for(size_type __i = 0; __i < __n; __i++)
101 __res[__i] = __default_random_generator(_M_iseed);
109 void operator() (size_type __n, pointer __res, std::vector<int> & __iseed) {
111 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
113 std::lock_guard<std::mutex> guard(_multiple_number_generation_mutex);
119 for(size_type __i = 0; __i < __n; __i++)
120 __res[__i] = __default_random_generator(_M_iseed);
124 void randomize(
void *__iseed) {
125 int *__new_seed = (
int*) __iseed;
126 _M_iseed[0] = __new_seed[0];
127 _M_iseed[1] = __new_seed[1];
130 void set_status(
const std::vector<int> & __iseed) {
131 assert(__iseed.size() >= 2);
132 _M_iseed[0] = __iseed[0];
133 _M_iseed[1] = __iseed[1];
136 void get_status(std::vector<int> & __iseed) {
138 __iseed[0] = _M_iseed[0];
139 __iseed[1] = _M_iseed[1];
143 inline static value_type min() {
return 0;}
144 inline static value_type max() {
return 2147483647;}
147 void print_info(std::ostream& __os = std::cout) {
148 __os<<
"BasicRandom<int> : "<<_M_iseed[0]<<
", "<<_M_iseed[1]<<std::endl;
153 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
154 static std::mutex _multiple_number_generation_mutex;
163 template<>
class BasicRandom<double> {
165 typedef double value_type;
166 typedef unsigned int size_type;
167 typedef value_type* pointer;
170 explicit BasicRandom(
int __s1 = 12345,
int __s2 = 67890) {
177 value_type operator() () {
178 return 4.6566128752457969241e-10*__default_random_generator(_M_iseed);
183 void operator() (size_type __n, pointer __res) {
184 for(size_type __i = 0; __i < __n; __i++)
185 __res[__i] =
this ->
operator()();
193 void operator() (size_type __n, pointer __res, std::vector<int> & __iseed) {
195 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
197 std::lock_guard<std::mutex> guard(_multiple_number_generation_mutex);
203 for(size_type __i = 0; __i < __n; __i++)
204 __res[__i] =
this ->
operator()();
208 void randomize(
void *__iseed) {
209 int *__new_seed = (
int*) __iseed;
210 _M_iseed[0] = __new_seed[0];
211 _M_iseed[1] = __new_seed[1];
214 void set_status(
const std::vector<int> & __iseed) {
215 assert(__iseed.size() >= 2);
216 _M_iseed[0] = __iseed[0];
217 _M_iseed[1] = __iseed[1];
220 void get_status(std::vector<int> & __iseed) {
222 __iseed[0] = _M_iseed[0];
223 __iseed[1] = _M_iseed[1];
227 inline static value_type min() {
return 0.0;}
229 inline static value_type max() {
return 1.0;}
232 void print_info(std::ostream& __os = std::cout) {
233 __os<<
"BasicRandom<double> : "<<_M_iseed[0]<<
", "<<_M_iseed[1]<<std::endl;
238 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
239 static std::mutex _multiple_number_generation_mutex;
244 extern BasicRandom<int> _G_random_int;
245 extern BasicRandom<double> _G_random_double;
248 FASTJET_END_NAMESPACE