1 //--------------------------------------------------------------------------
4 // This software is part of the EvtGen package developed jointly
5 // for the BaBar and CLEO collaborations. If you use all or part
6 // of it, please give an appropriate acknowledgement.
8 // Copyright Information: See EvtGen/COPYRIGHT
9 // Copyright (C) 1998 Caltech, UCSB
11 // Module: EvtRandom.cc
13 // Description: routines to get random numbers from
14 // random number generator.
16 // Modification history:
18 // DJL/RYD September 25, 1996 Module created
20 //------------------------------------------------------------------------
22 #include "EvtGenBase/EvtPatches.hh"
28 #include "EvtGenBase/EvtRandomEngine.hh"
29 #include "EvtGenBase/EvtRandom.hh"
30 #include "EvtGenBase/EvtReport.hh"
31 #include "EvtGenBase/EvtConst.hh"
36 EvtRandomEngine* EvtRandom::_randomEngine=0;
38 void EvtRandom::setRandomEngine(EvtRandomEngine* randomEngine){
39 _randomEngine=randomEngine;
43 double EvtRandom::random(){
45 if (_randomEngine==0){
46 report(ERROR,"EvtGen") <<"No random engine available in "
47 <<"EvtRandom::random()."<<endl;
51 return _randomEngine->random();
56 // Random number routine to generate numbers between
57 // min and max. By djl on July 27, 1995.
58 double EvtRandom::Flat( double min, double max){
61 report(ERROR,"EvtGen") << "min>max in EvtRandom::Flat(" << min << "," << max << ")" <<endl;
65 return EvtRandom::random()*( max - min )+min;
69 double EvtRandom::Flat(double max){
71 return max*EvtRandom::random();
75 double EvtRandom::Flat(){
77 return EvtRandom::random();
81 double EvtRandom::Gaussian(){
83 double x=EvtRandom::random();
84 double y=EvtRandom::random();
86 return cos(x*EvtConst::twoPi)*sqrt(-2.0*log(1-y));