49static const int MarkerLen = 64;
54int HepJamesRandom::numEngines = 0;
57int HepJamesRandom::maxIndex = 215;
72 int cycle = std::abs(
int(numEngines/maxIndex));
73 int curIndex = std::abs(
int(numEngines%maxIndex));
75 long mask = ((cycle & 0x007fffff) << 8);
88 int cycle = std::abs(
int(rowIndex/maxIndex));
89 int row = std::abs(
int(rowIndex%maxIndex));
90 int col = std::abs(
int(colIndex%2));
91 long mask = ((cycle & 0x000007ff) << 20);
93 seed = (seeds[col])^mask;
108 std::ofstream outFile( filename, std::ios::out ) ;
110 if (!outFile.bad()) {
112 std::vector<unsigned long> v =
put();
113 for (
unsigned int i=0; i<v.size(); ++i) {
114 outFile << v[i] <<
"\n";
122 std::ifstream inFile( filename, std::ios::in);
124 std::cerr <<
" -- Engine state remains unchanged\n";
128 std::vector<unsigned long> v;
133 inFile.clear(std::ios::badbit | inFile.rdstate());
134 std::cerr <<
"\nJamesRandom state (vector) description improper."
135 <<
"\nrestoreStatus has failed."
136 <<
"\nInput stream is probably mispositioned now." << std::endl;
145 if (!inFile.bad() && !inFile.eof()) {
147 for (
int i=0; i<97; ++i)
149 inFile >> c; inFile >> cd; inFile >> cm;
159 std::cout << std::endl;
160 std::cout <<
"----- HepJamesRandom engine status -----" << std::endl;
161 std::cout <<
" Initial seed = " <<
theSeed << std::endl;
162 std::cout <<
" u[] = ";
163 for (
int i=0; i<97; ++i)
164 std::cout << u[i] <<
" ";
165 std::cout << std::endl;
166 std::cout <<
" c = " << c <<
", cd = " << cd <<
", cm = " << cm
168 std::cout <<
" i97 = " << i97 <<
", u[i97] = " << u[i97] << std::endl;
169 std::cout <<
" j97 = " << j97 <<
", u[j97] = " << u[j97] << std::endl;
170 std::cout <<
"----------------------------------------" << std::endl;
186 std::cout <<
"Seed for HepJamesRandom must be non-negative\n"
187 <<
"Seed value supplied was " << seed
188 <<
"\nUsing its absolute value instead\n";
192 long ij = seed/30082;
193 long kl = seed - 30082*ij;
194 long i = (ij/177) % 177 + 2;
195 long j = ij % 177 + 2;
196 long k = (kl/169) % 178 + 1;
201 for ( n = 1 ; n < 98 ; n++ ) {
204 for ( m = 1 ; m < 25 ; m++) {
205 mm = ( ( (i*j) % 179 ) * k ) % 179;
209 l = ( 53 * l + 1 ) % 169;
210 if ( (l*mm % 64 ) >= 32 )
216 c = 362436.0 / 16777216.0;
217 cd = 7654321.0 / 16777216.0;
218 cm = 16777213.0 / 16777216.0;
227 setSeed(seeds ? *seeds : 19780503L, 0);
236 uni = u[i97] - u[j97];
237 if ( uni < 0.0 ) uni++;
240 if (i97 == 0) i97 = 96;
243 if (j97 == 0) j97 = 96;
247 if (c < 0.0) c += cm;
250 if (uni < 0.0) uni += 1.0;
251 }
while ( uni <= 0.0 || uni >= 1.0 );
261 for (i=0; i<size; ++i) {
266HepJamesRandom::operator
unsigned int() {
267 return ((
unsigned int)(flat() * exponent_bit_32()) & 0xffffffff ) |
268 (((
unsigned int)( u[i97] * exponent_bit_32())>>16) & 0xff);
272 char beginMarker[] =
"JamesRandom-begin";
273 os << beginMarker <<
"\nUvec\n";
274 std::vector<unsigned long> v =
put();
275 for (
unsigned int i=0; i<v.size(); ++i) {
282 std::vector<unsigned long> v;
283 v.push_back (engineIDulong<HepJamesRandom>());
284 std::vector<unsigned long> t;
285 for (
int i=0; i<97; ++i) {
287 v.push_back(t[0]); v.push_back(t[1]);
290 v.push_back(t[0]); v.push_back(t[1]);
292 v.push_back(t[0]); v.push_back(t[1]);
294 v.push_back(t[0]); v.push_back(t[1]);
295 v.push_back(
static_cast<unsigned long>(j97));
301 char beginMarker [MarkerLen];
307 if (strcmp(beginMarker,
"JamesRandom-begin")) {
308 is.clear(std::ios::badbit | is.rdstate());
309 std::cerr <<
"\nInput stream mispositioned or"
310 <<
"\nJamesRandom state description missing or"
311 <<
"\nwrong engine type found." << std::endl;
318 return "JamesRandom-begin";
323 std::vector<unsigned long> v;
328 is.clear(std::ios::badbit | is.rdstate());
329 std::cerr <<
"\nJamesRandom state (vector) description improper."
330 <<
"\ngetState() has failed."
331 <<
"\nInput stream is probably mispositioned now." << std::endl;
343 char endMarker [MarkerLen];
344 for (
int i=0; i<97; ++i) {
347 is >> c; is >> cd; is >> cm;
352 if(strcmp(endMarker,
"JamesRandom-end")) {
353 is.clear(std::ios::badbit | is.rdstate());
354 std::cerr <<
"\nJamesRandom state description incomplete."
355 <<
"\nInput stream is probably mispositioned now." << std::endl;
366 if ( (v[0] & 0xffffffffUL) != engineIDulong<HepJamesRandom>()) {
368 "\nHepJamesRandom get:state vector has wrong ID word - state unchanged\n";
377 "\nHepJamesRandom get:state vector has wrong length - state unchanged\n";
380 std::vector<unsigned long> t(2);
381 for (
int i=0; i<97; ++i) {
382 t[0] = v[2*i+1]; t[1] = v[2*i+2];
static double longs2double(const std::vector< unsigned long > &v)
static std::vector< unsigned long > dto2longs(double d)
void flatArray(const int size, double *vect)
static std::string beginTag()
static std::string engineName()
void setSeeds(const long *seeds, int dum=0)
virtual std::istream & getState(std::istream &is)
virtual ~HepJamesRandom()
std::vector< unsigned long > put() const
void setSeed(long seed, int dum=0)
virtual std::istream & get(std::istream &is)
void saveStatus(const char filename[]="JamesRand.conf") const
void restoreStatus(const char filename[]="JamesRand.conf")
static const unsigned int VECTOR_STATE_SIZE
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
static void getTheTableSeeds(long *seeds, int index)
bool possibleKeywordInput(IS &is, const std::string &key, T &t)