]>
Commit | Line | Data |
---|---|---|
da0e9ce3 | 1 | //-------------------------------------------------------------------------- |
2 | // | |
3 | // Environment: | |
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. | |
7 | // | |
8 | // Copyright Information: See EvtGen/COPYRIGHT | |
9 | // Copyright (C) 1998 Caltech, UCSB | |
10 | // | |
11 | // Module: EvtRandom.cc | |
12 | // | |
13 | // Description: routines to get random numbers from | |
14 | // random number generator. | |
15 | // | |
16 | // Modification history: | |
17 | // | |
18 | // DJL/RYD September 25, 1996 Module created | |
19 | // | |
20 | //------------------------------------------------------------------------ | |
21 | // | |
22 | #include "EvtGenBase/EvtPatches.hh" | |
23 | ||
24 | #include <stdlib.h> | |
25 | #include <stdio.h> | |
26 | #include <math.h> | |
27 | #include <iostream> | |
28 | #include "EvtGenBase/EvtRandomEngine.hh" | |
29 | #include "EvtGenBase/EvtRandom.hh" | |
30 | #include "EvtGenBase/EvtReport.hh" | |
31 | #include "EvtGenBase/EvtConst.hh" | |
32 | ||
33 | using std::endl; | |
34 | ||
35 | ||
36 | EvtRandomEngine* EvtRandom::_randomEngine=0; | |
37 | ||
38 | void EvtRandom::setRandomEngine(EvtRandomEngine* randomEngine){ | |
39 | _randomEngine=randomEngine; | |
40 | } | |
41 | ||
42 | ||
43 | double EvtRandom::random(){ | |
44 | ||
45 | if (_randomEngine==0){ | |
46 | report(ERROR,"EvtGen") <<"No random engine available in " | |
47 | <<"EvtRandom::random()."<<endl; | |
48 | ::abort(); | |
49 | } | |
50 | ||
51 | return _randomEngine->random(); | |
52 | ||
53 | } | |
54 | ||
55 | ||
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){ | |
59 | ||
60 | if ( min > max ) { | |
61 | report(ERROR,"EvtGen") << "min>max in EvtRandom::Flat(" << min << "," << max << ")" <<endl; | |
62 | ::abort(); | |
63 | } | |
64 | ||
65 | return EvtRandom::random()*( max - min )+min; | |
66 | ||
67 | } | |
68 | ||
69 | double EvtRandom::Flat(double max){ | |
70 | ||
71 | return max*EvtRandom::random(); | |
72 | ||
73 | } | |
74 | ||
75 | double EvtRandom::Flat(){ | |
76 | ||
77 | return EvtRandom::random(); | |
78 | ||
79 | } | |
80 | ||
81 | double EvtRandom::Gaussian(){ | |
82 | ||
83 | double x=EvtRandom::random(); | |
84 | double y=EvtRandom::random(); | |
85 | ||
86 | return cos(x*EvtConst::twoPi)*sqrt(-2.0*log(1-y)); | |
87 | ||
88 | } | |
89 | ||
90 |