4 // -----------------------------------------------------------------------
7 // inlined functions implementation file
8 // -----------------------------------------------------------------------
9 // This file is part of Geant4 (simulation toolkit for HEP).
11 // =======================================================================
12 // Gabriele Cosmo - Created: 5th September 1995
13 // Peter Urban - ShootBit() and related stuff added: 5th Sep 1996
14 // Gabriele Cosmo - Additional methods to fill arrays specifying
15 // boundaries: 24th Jul 1997
16 // - Fixed bug in shootInt(m,n): 25th Sep 1997
17 // J.Marraffino - Added default arguments as attributes: 16th Feb 1998
18 // M.Fischler - Corrected initialization of deleteEngine which should
19 // be true for all constructors taking HepRandomEngine*.
20 // =======================================================================
24 inline RandFlat::RandFlat(HepRandomEngine & anEngine)
25 : HepRandom(), firstUnusedBit(0), localEngine(&anEngine, do_nothing_deleter()),
26 defaultWidth(1.0), defaultA(0.0), defaultB(1.0) {}
28 inline RandFlat::RandFlat(HepRandomEngine & anEngine, double width )
29 : HepRandom(), firstUnusedBit(0), localEngine(&anEngine, do_nothing_deleter()),
30 defaultWidth(width), defaultA(0.0), defaultB(width) {}
32 inline RandFlat::RandFlat(HepRandomEngine & anEngine, double a,
34 : HepRandom(), firstUnusedBit(0), localEngine(&anEngine, do_nothing_deleter()),
35 defaultWidth(b-a), defaultA(a), defaultB(b) {}
37 inline RandFlat::RandFlat(HepRandomEngine * anEngine)
38 : HepRandom(), firstUnusedBit(0), localEngine(anEngine),
39 defaultWidth(1.0), defaultA(0.0), defaultB(1.0) {}
41 inline RandFlat::RandFlat(HepRandomEngine * anEngine, double width )
42 : HepRandom(), firstUnusedBit(0), localEngine(anEngine),
43 defaultWidth(width), defaultA(0.0), defaultB(width) {}
45 inline RandFlat::RandFlat(HepRandomEngine * anEngine, double a,
47 : HepRandom(), firstUnusedBit(0), localEngine(anEngine),
48 defaultWidth(b-a), defaultA(a), defaultB(b) {}
50 inline double RandFlat::shoot(double a, double b) {
51 return (b-a)* shoot() + a;
54 inline double RandFlat::shoot(double width) {
55 return width * shoot();
58 inline long RandFlat::shootInt(long n) {
59 return long(shoot()*double(n));
62 inline long RandFlat::shootInt(long a1, long n) {
63 return long(shoot()*double(n-a1)) + a1;
66 inline void RandFlat::shootBits() {
67 const double factor= 2.0*MSB; // this should fit into a double!
68 staticFirstUnusedBit= MSB;
69 staticRandomInt= (unsigned long)(factor*shoot());
72 inline int RandFlat::shootBit() {
73 if (staticFirstUnusedBit==0)
75 unsigned long temp= staticFirstUnusedBit&staticRandomInt;
76 staticFirstUnusedBit>>= 1;
80 //---------------------
82 inline double RandFlat::shoot(HepRandomEngine* anEngine) {
83 return anEngine->flat();
87 inline double RandFlat::shoot(HepRandomEngine* anEngine,
89 return (b-a)* anEngine->flat() + a;
92 inline double RandFlat::shoot(HepRandomEngine* anEngine,
94 return width * anEngine->flat();
97 inline long RandFlat::shootInt(HepRandomEngine* anEngine,
99 return long(anEngine->flat()*double(n));
102 inline long RandFlat::shootInt(HepRandomEngine* anEngine,
104 return long(double(n-a1)*anEngine->flat()) + a1;
107 inline void RandFlat::shootArray(HepRandomEngine* anEngine,
108 const int size, double* vect) {
109 anEngine->flatArray(size,vect);
112 inline void RandFlat::shootBits(HepRandomEngine* engine) {
113 const double factor= 2.0*MSB; // this should fit into a double!
114 staticFirstUnusedBit= MSB;
115 staticRandomInt= (unsigned long)(factor*shoot(engine));
118 inline int RandFlat::shootBit(HepRandomEngine* engine) {
119 if (staticFirstUnusedBit==0)
121 unsigned long temp= staticFirstUnusedBit&staticRandomInt;
122 staticFirstUnusedBit>>= 1;
126 //---------------------
128 inline double RandFlat::fire() {
129 return (defaultB-defaultA)*localEngine->flat()+defaultA;
132 inline double RandFlat::fire(double a, double b) {
133 return (b-a)* localEngine->flat() + a;
136 inline double RandFlat::fire(double width) {
137 return width * localEngine->flat();
140 inline long RandFlat::fireInt(long n) {
141 return long(localEngine->flat()*double(n));
144 inline long RandFlat::fireInt(long a1, long n) {
145 return long(localEngine->flat()*double(n-a1)) + a1;
148 inline void RandFlat::fireBits() {
149 const double factor= 2.0*MSB; // this should fit into a double!
151 randomInt= (unsigned long)(factor*localEngine->flat());
154 inline int RandFlat::fireBit() {
155 if (firstUnusedBit==0)
157 unsigned long temp= firstUnusedBit&randomInt;