00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ThePEG_UseRandom_H
00010 #define ThePEG_UseRandom_H
00011
00012
00013 #include "ThePEG/Repository/RandomGenerator.h"
00014
00015 namespace ThePEG {
00016
00033 class UseRandom {
00034
00035 public:
00036
00040 UseRandom() : randomPushed(false) {}
00041
00045 UseRandom(const UseRandom &) : randomPushed(false) {}
00046
00051 UseRandom(const RanGenPtr & r) : randomPushed(false) {
00052 if ( r ) {
00053 theRandomStack.push_back(r);
00054 randomPushed = true;
00055 }
00056 }
00057
00062 ~UseRandom() { if ( randomPushed ) theRandomStack.pop_back(); }
00063
00064 public:
00065
00069 static RandomGenerator & current() { return *theRandomStack.back(); }
00070
00074
00075
00076
00077
00082 static double rnd() { return current().rnd(); }
00083
00088 static RandomGenerator::RndVector rndvec(int n) {
00089 return current().rndvec(n);
00090 }
00091
00096 template <typename Unit>
00097 static Unit rnd(Unit xu) { return current().rnd(xu); }
00098
00103 template <typename Unit>
00104 static Unit rnd(Unit xl, Unit xu) {
00105 return current().rnd(xl, xu);
00106 }
00107
00111 static bool rndbool(double p = 0.5) {
00112 return current().rndbool(p);
00113 }
00114
00118 static bool rndbool(double p1, double p2) {
00119 return current().rndbool(p1, p2);
00120 }
00121
00126 static int rndsign(double p1, double p2, double p3) {
00127 return current().rndsign(p1, p2, p3);
00128 }
00129
00134 static int rnd2(double p0, double p1) {
00135 return current().rnd2(p0, p1);
00136 }
00137
00142 static int rnd3(double p0, double p1, double p2) {
00143 return current().rnd3(p0, p1, p2);
00144 }
00145
00150 static int rnd4(double p0, double p1, double p2, double p3) {
00151 return current().rnd4(p0, p1, p2, p3);
00152 }
00153
00157 static long irnd(long xu = 2) { return long(rnd() * xu); }
00158
00162 static long irnd(long xl, long xu) { return xl + irnd(xu-xl); }
00163
00168 static double rndExp() { return current().rndExp(); }
00169
00174 template <typename Unit>
00175 static Unit rndExp(Unit mean) { return current().rndExp(mean); }
00176
00181 static double rndGauss() { return current().rndGauss(); }
00182
00187 template <typename Unit>
00188 static Unit rndGauss(Unit sigma, Unit mean = Unit()) {
00189 return current().rndGauss(sigma, mean);
00190 }
00191
00197 template <typename Unit>
00198 static Unit rndBW(Unit mean, Unit gamma) {
00199 return current().rndBW(mean, gamma);
00200 }
00201
00208 template <typename Unit>
00209 static Unit rndBW(Unit mean, Unit gamma, Unit cut) {
00210 return current().rndBW(mean, gamma, cut);
00211 }
00212
00217 template <typename Unit>
00218 static Unit rndRelBW(Unit mean, Unit gamma) {
00219 return current().rndRelBW(mean, gamma);
00220 }
00221
00228 template <typename Unit>
00229 static Unit rndRelBW(Unit mean, Unit gamma, Unit cut) {
00230 return current().rndRelBW(mean, gamma, cut);
00231 }
00232
00237 static long rndPoisson(double mean) {
00238 return current().rndPoisson(mean);
00239 }
00240
00241 private:
00242
00246 static vector<RanGenPtr> theRandomStack;
00247
00252 bool randomPushed;
00253
00254 private:
00255
00259 UseRandom & operator=(const UseRandom &);
00260
00261 };
00262
00263 }
00264
00265 #endif