00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 namespace CLHEP {
00023
00024 inline RandFlat::RandFlat(HepRandomEngine & anEngine)
00025 : HepRandom(), firstUnusedBit(0), localEngine(&anEngine, do_nothing_deleter()),
00026 defaultWidth(1.0), defaultA(0.0), defaultB(1.0) {}
00027
00028 inline RandFlat::RandFlat(HepRandomEngine & anEngine, double width )
00029 : HepRandom(), firstUnusedBit(0), localEngine(&anEngine, do_nothing_deleter()),
00030 defaultWidth(width), defaultA(0.0), defaultB(width) {}
00031
00032 inline RandFlat::RandFlat(HepRandomEngine & anEngine, double a,
00033 double b )
00034 : HepRandom(), firstUnusedBit(0), localEngine(&anEngine, do_nothing_deleter()),
00035 defaultWidth(b-a), defaultA(a), defaultB(b) {}
00036
00037 inline RandFlat::RandFlat(HepRandomEngine * anEngine)
00038 : HepRandom(), firstUnusedBit(0), localEngine(anEngine),
00039 defaultWidth(1.0), defaultA(0.0), defaultB(1.0) {}
00040
00041 inline RandFlat::RandFlat(HepRandomEngine * anEngine, double width )
00042 : HepRandom(), firstUnusedBit(0), localEngine(anEngine),
00043 defaultWidth(width), defaultA(0.0), defaultB(width) {}
00044
00045 inline RandFlat::RandFlat(HepRandomEngine * anEngine, double a,
00046 double b )
00047 : HepRandom(), firstUnusedBit(0), localEngine(anEngine),
00048 defaultWidth(b-a), defaultA(a), defaultB(b) {}
00049
00050 inline double RandFlat::shoot(double a, double b) {
00051 return (b-a)* shoot() + a;
00052 }
00053
00054 inline double RandFlat::shoot(double width) {
00055 return width * shoot();
00056 }
00057
00058 inline long RandFlat::shootInt(long n) {
00059 return long(shoot()*double(n));
00060 }
00061
00062 inline long RandFlat::shootInt(long a, long b) {
00063 return long(shoot()*double(b-a)) + a;
00064 }
00065
00066 inline void RandFlat::shootBits() {
00067 const double factor= 2.0*MSB;
00068 staticFirstUnusedBit= MSB;
00069 staticRandomInt= (unsigned long)(factor*shoot());
00070 }
00071
00072 inline int RandFlat::shootBit() {
00073 if (staticFirstUnusedBit==0)
00074 shootBits();
00075 unsigned long temp= staticFirstUnusedBit&staticRandomInt;
00076 staticFirstUnusedBit>>= 1;
00077 return temp!=0;
00078 }
00079
00080
00081
00082 inline double RandFlat::shoot(HepRandomEngine* anEngine) {
00083 return anEngine->flat();
00084 }
00085
00086
00087 inline double RandFlat::shoot(HepRandomEngine* anEngine,
00088 double a, double b) {
00089 return (b-a)* anEngine->flat() + a;
00090 }
00091
00092 inline double RandFlat::shoot(HepRandomEngine* anEngine,
00093 double width) {
00094 return width * anEngine->flat();
00095 }
00096
00097 inline long RandFlat::shootInt(HepRandomEngine* anEngine,
00098 long n) {
00099 return long(anEngine->flat()*double(n));
00100 }
00101
00102 inline long RandFlat::shootInt(HepRandomEngine* anEngine,
00103 long a, long b) {
00104 return long(double(b-a)*anEngine->flat()) + a;
00105 }
00106
00107 inline void RandFlat::shootArray(HepRandomEngine* anEngine,
00108 const int size, double* vect) {
00109 anEngine->flatArray(size,vect);
00110 }
00111
00112 inline void RandFlat::shootBits(HepRandomEngine* engine) {
00113 const double factor= 2.0*MSB;
00114 staticFirstUnusedBit= MSB;
00115 staticRandomInt= (unsigned long)(factor*shoot(engine));
00116 }
00117
00118 inline int RandFlat::shootBit(HepRandomEngine* engine) {
00119 if (staticFirstUnusedBit==0)
00120 shootBits(engine);
00121 unsigned long temp= staticFirstUnusedBit&staticRandomInt;
00122 staticFirstUnusedBit>>= 1;
00123 return temp!=0;
00124 }
00125
00126
00127
00128 inline double RandFlat::fire() {
00129 return (defaultB-defaultA)*localEngine->flat()+defaultA;
00130 }
00131
00132 inline double RandFlat::fire(double a, double b) {
00133 return (b-a)* localEngine->flat() + a;
00134 }
00135
00136 inline double RandFlat::fire(double width) {
00137 return width * localEngine->flat();
00138 }
00139
00140 inline long RandFlat::fireInt(long n) {
00141 return long(localEngine->flat()*double(n));
00142 }
00143
00144 inline long RandFlat::fireInt(long a, long b) {
00145 return long(localEngine->flat()*double(b-a)) + a;
00146 }
00147
00148 inline void RandFlat::fireBits() {
00149 const double factor= 2.0*MSB;
00150 firstUnusedBit= MSB;
00151 randomInt= (unsigned long)(factor*localEngine->flat());
00152 }
00153
00154 inline int RandFlat::fireBit() {
00155 if (firstUnusedBit==0)
00156 fireBits();
00157 unsigned long temp= firstUnusedBit&randomInt;
00158 firstUnusedBit>>= 1;
00159 return temp!=0;
00160 }
00161
00162 }