55 const int maxIndex = 215;
75 int numEngines = numberOfEngines++;
76 int cycle =
std::abs(
int(numEngines/maxIndex));
77 int curIndex =
std::abs(
int(numEngines%maxIndex));
79 long mask = ((cycle & 0x007fffff) << 8);
92 int cycle =
std::abs(
int(rowIndex/maxIndex));
93 int row =
std::abs(
int(rowIndex%maxIndex));
95 long mask = ((cycle & 0x000007ff) << 20);
97 seed = (seeds[
col])^mask;
112 std::ofstream outFile( filename, std::ios::out ) ;
114 if (!outFile.bad()) {
116 std::vector<unsigned long>
v =
put();
117 for (
unsigned int i=0; i<v.size(); ++i) {
118 outFile << v[i] <<
"\n";
128 std::cerr <<
" -- Engine state remains unchanged\n";
132 std::vector<unsigned long>
v;
137 inFile.clear(std::ios::badbit | inFile.rdstate());
138 std::cerr <<
"\nJamesRandom state (vector) description improper."
139 <<
"\nrestoreStatus has failed."
140 <<
"\nInput stream is probably mispositioned now." << std::endl;
149 if (!inFile.bad() && !inFile.eof()) {
151 for (
int i=0; i<97; ++i)
153 inFile >>
c; inFile >>
cd; inFile >>
cm;
163 std::cout << std::endl;
164 std::cout <<
"----- HepJamesRandom engine status -----" << std::endl;
165 std::cout <<
" Initial seed = " <<
theSeed << std::endl;
166 std::cout <<
" u[] = ";
167 for (
int i=0; i<97; ++i)
168 std::cout <<
u[i] <<
" ";
169 std::cout << std::endl;
170 std::cout <<
" c = " <<
c <<
", cd = " <<
cd <<
", cm = " <<
cm
172 std::cout <<
" i97 = " <<
i97 <<
", u[i97] = " <<
u[
i97] << std::endl;
173 std::cout <<
" j97 = " <<
j97 <<
", u[j97] = " <<
u[
j97] << std::endl;
174 std::cout <<
"----------------------------------------" << std::endl;
190 std::cout <<
"Seed for HepJamesRandom must be non-negative\n"
191 <<
"Seed value supplied was " << seed
192 <<
"\nUsing its absolute value instead\n";
196 long ij = seed/30082;
197 long kl = seed - 30082*ij;
198 long i = (ij/177) % 177 + 2;
199 long j = ij % 177 + 2;
200 long k = (kl/169) % 178 + 1;
205 for ( n = 1 ; n < 98 ; n++ ) {
208 for ( m = 1 ; m < 25 ; m++) {
209 mm = ( ( (i*j) % 179 ) *
k ) % 179;
213 l = ( 53 * l + 1 ) % 169;
214 if ( (l*mm % 64 ) >= 32 )
220 c = 362436.0 / 16777216.0;
221 cd = 7654321.0 / 16777216.0;
222 cm = 16777213.0 / 16777216.0;
231 setSeed(seeds ? *seeds : 19780503
L, 0);
241 if ( uni < 0.0 ) uni++;
251 if (
c < 0.0)
c +=
cm;
254 if (uni < 0.0) uni += 1.0;
255 }
while ( uni <= 0.0 || uni >= 1.0 );
265 for (i=0; i<size; ++i) {
270 HepJamesRandom::operator double() {
274 HepJamesRandom::operator float() {
275 return float(
flat() );
278 HepJamesRandom::operator
unsigned int() {
279 return ((
unsigned int)(
flat() * exponent_bit_32()) & 0xffffffff ) |
280 (((
unsigned int)(
u[i97] * exponent_bit_32())>>16) & 0xff);
284 char beginMarker[] =
"JamesRandom-begin";
285 os << beginMarker <<
"\nUvec\n";
286 std::vector<unsigned long>
v =
put();
287 for (
unsigned int i=0; i<v.size(); ++i) {
294 std::vector<unsigned long>
v;
295 v.push_back (engineIDulong<HepJamesRandom>());
296 std::vector<unsigned long>
t;
297 for (
int i=0; i<97; ++i) {
299 v.push_back(t[0]); v.push_back(t[1]);
302 v.push_back(t[0]); v.push_back(t[1]);
304 v.push_back(t[0]); v.push_back(t[1]);
306 v.push_back(t[0]); v.push_back(t[1]);
307 v.push_back(static_cast<unsigned long>(
j97));
319 if (strcmp(beginMarker,
"JamesRandom-begin")) {
320 is.clear(std::ios::badbit | is.rdstate());
321 std::cerr <<
"\nInput stream mispositioned or"
322 <<
"\nJamesRandom state description missing or"
323 <<
"\nwrong engine type found." << std::endl;
330 return "JamesRandom-begin";
335 std::vector<unsigned long>
v;
340 is.clear(std::ios::badbit | is.rdstate());
341 std::cerr <<
"\nJamesRandom state (vector) description improper."
342 <<
"\ngetState() has failed."
343 <<
"\nInput stream is probably mispositioned now." << std::endl;
356 for (
int i=0; i<97; ++i) {
359 is >>
c; is >>
cd; is >>
cm;
364 if(strcmp(endMarker,
"JamesRandom-end")) {
365 is.clear(std::ios::badbit | is.rdstate());
366 std::cerr <<
"\nJamesRandom state description incomplete."
367 <<
"\nInput stream is probably mispositioned now." << std::endl;
378 if ( (v[0] & 0xffffffffUL) != engineIDulong<HepJamesRandom>()) {
380 "\nHepJamesRandom get:state vector has wrong ID word - state unchanged\n";
389 "\nHepJamesRandom get:state vector has wrong length - state unchanged\n";
392 std::vector<unsigned long>
t(2);
393 for (
int i=0; i<97; ++i) {
394 t[0] = v[2*i+1]; t[1] = v[2*i+2];