1 #include "StarRandom.h"
5 #include "Math/GSLRndmEngines.h"
16 ROOT::Math::GSLRandomEngine *StarRandom::mEngine = 0;
32 void gsl_rng_env_setup();
33 unsigned long gsl_rng_default_seed;
43 StarRandom::StarRandom() : TObject(), mSeed(0), mState()
48 StarRandom::~StarRandom()
59 if ( !gStarRandom ) gStarRandom =
new _Random();
62 Instance().Warning(
"StarRandom::capture()",
"Capturing gRandom");
65 gRandom = gStarRandom;
69 Double_t
StarRandom::flat(
const Double_t mn,
const Double_t mx )
const { assert(mx>mn);
return mn + (mx - mn) *
flat(); }
70 Double_t
StarRandom::expo(
const Double_t mu )
const {
return mEngine->Exponential( mu ); }
72 Double_t
StarRandom::gauss(
const Double_t sigma )
const {
return mEngine->Gaussian( sigma ); }
76 mEngine->Gaussian2D( sx, sy, rho, x, y );
77 return TVector2( x, y );
95 if ( !mEngine ) mEngine =
new ROOT::Math::GSLRandomEngine();
96 mEngine -> Initialize();
97 LOG_INFO <<
"Initialize random number generator " << mEngine->Name() << endm;
99 if ( !gsl_rng_default_seed )
102 long time = gSystem->Now();
103 long pid = gSystem->GetPid();
104 seed( time|(pid<<16) );
108 seed( gsl_rng_default_seed );
111 LOG_INFO <<
"Initialize random number seed " << sInstance->mSeed << endm;
127 Int_t myseed1 = seed1;
128 Int_t myseed2 = seed2;
129 seed( (myseed1<<16)|(myseed2) );
Double_t operator()() const
Return a random number uniformly distributed between 0 and 1.
Double_t expo(const Double_t mu) const
Return a random number distribted according to exp(-mu)
Double_t gauss(const Double_t sigma) const
Return a random number distributed according to a gaussian with specified sigma.
Double_t landau() const
Return a random number distributed according to a landau.
static StarRandom & Instance()
Obtain the single instance of the random number generator.
UInt_t poisson(const Double_t mu) const
A class for providing random number generation.
Double_t flat() const
Return a random number uniformly distributed between 0 and 1.
static void set(ROOT::Math::GSLRandomEngine *engine)
Set the random number generator engine.
static void seed(UInt_t s)
TVector2 gauss2d(const Double_t sx, const Double_t sy, const Double_t rho) const
Returns a pair of random numbers generated according to a 2D gaussian.
static void capture()
Capture gRandom random number generator.