52 #include "JamesRandom.h"
54 HepJamesRandom::HepJamesRandom(
long seed)
60 HepJamesRandom::~HepJamesRandom() {}
65 if ((
this != &p) && (&p)) {
66 theSeed = p.getSeed();
68 for (HepInt i=0; i<97; ++i)
70 c = p.c; cd = p.cd; cm = p.cm;
71 jpos = HepInt(p.pj97-p.u);
73 pi97 = &u[ipos]; pj97 = &u[jpos];
80 if ((
this != &p) && (&p)) {
81 theSeed = p.getSeed();
83 for (HepInt i=0; i<97; ++i)
85 c = p.c; cd = p.cd; cm = p.cm;
86 jpos = HepInt(p.pj97-p.u);
88 pi97 = &u[ipos]; pj97 = &u[jpos];
93 void HepJamesRandom::saveStatus()
const
95 ofstream outFile(
"JamesRand.conf", std::ios::out ) ;
98 HepInt pos = HepInt(pj97-u);
99 outFile << theSeed << endl;
100 for (HepInt i=0; i<97; ++i)
101 outFile << u[i] <<
" ";
103 outFile << c <<
" " << cd <<
" " << cm << endl;
104 outFile << pos << endl;
108 void HepJamesRandom::restoreStatus()
111 ifstream inFile(
"JamesRand.conf", std::ios::in);
113 if (!inFile.bad() && !inFile.eof()) {
115 for (HepInt i=0; i<97; ++i)
117 inFile >> c; inFile >> cd; inFile >> cm;
125 void HepJamesRandom::showStatus()
const
128 cout <<
"----- HepJamesRandom engine status -----" << endl;
129 cout <<
" Initial seed = " << theSeed << endl;
131 for (HepInt i=0; i<97; ++i)
134 cout <<
" c = " << c <<
", cd = " << cd <<
", cm = " << cm << endl;
135 cout <<
" pi97 = " << pi97 <<
", *pi97 = " << *pi97 << endl;
136 cout <<
" pj97 = " << pj97 <<
", *pj97 = " << *pj97 << endl;
137 cout <<
"----------------------------------------" << endl;
140 void HepJamesRandom::setSeed(
long seed, HepInt)
148 long ij = seed/30082;
149 long kl = seed - 30082*ij;
150 long i = (ij/177) % 177 + 2;
151 long j = ij % 177 + 2;
152 long k = (kl/169) % 178 + 1;
157 for ( n = 1 ; n < 98 ; n++ ) {
160 for ( m = 1 ; m < 25 ; m++) {
161 mm = ( ( (i*j) % 179 ) * k ) % 179;
165 l = ( 53 * l + 1 ) % 169;
166 if ( (l*mm % 64 ) >= 32 )
172 c = 362436.0 / 16777216.0;
173 cd = 7654321.0 / 16777216.0;
174 cm = 16777213.0 / 16777216.0;
179 void HepJamesRandom::setSeeds(
const long* seeds, HepInt)
181 setSeed(seeds ? *seeds : 19780503, 0);
185 HepDouble HepJamesRandom::flat()
191 if ( uni < 0.0 ) uni++;
194 if (pi97 == u) pi97 += 96;
197 if (pj97 == u) pj97 += 96;
201 if (c < 0.0) c += cm;
204 if (uni < 0.0) uni += 1.0;
205 }
while ( uni <= 0.0 || uni >= 1.0 );
210 void HepJamesRandom::flatArray(
const HepInt size, HepDouble* vect)
215 for (i=0; i<size; ++i) {
218 if ( uni < 0.0 ) uni++;
221 if (pi97 == u) pi97 += 96;
224 if (pj97 == u) pj97 += 96;
228 if (c < 0.0) c += cm;
231 if (uni < 0.0) uni += 1.0;
232 }
while ( uni <= 0.0 || uni >= 1.0 );
238 #ifndef ST_NO_TEMPLATE_DEF_ARGS
239 HepJamesRandom::flatArray(vector<HepDouble>& vec)
241 HepJamesRandom::flatArray(vector<HepDouble,allocator<HepDouble> >& vec)
246 for (
unsigned int i=0; i<vec.size(); ++i) {
249 if ( uni < 0.0 ) uni++;
252 if (pi97 == u) pi97 += 96;
255 if (pj97 == u) pj97 += 96;
259 if (c < 0.0) c += cm;
262 if (uni < 0.0) uni += 1.0;
263 }
while ( uni <= 0.0 || uni >= 1.0 );