59 const int maxIndex = 215;
62static const int MarkerLen = 64;
79 int numEngines = numberOfEngines++;
80 int cycle = std::abs(
int(numEngines/maxIndex));
81 int curIndex = std::abs(
int(numEngines%maxIndex));
83 long mask = ((cycle & 0x007fffff) << 8);
96 int cycle = std::abs(
int(rowIndex/maxIndex));
97 int row = std::abs(
int(rowIndex%maxIndex));
98 int col = std::abs(
int(colIndex%2));
99 long mask = ((cycle & 0x000007ff) << 20);
101 seed = (seeds[col])^mask;
116 std::ofstream outFile( filename, std::ios::out ) ;
118 if (!outFile.bad()) {
120 std::vector<unsigned long> v =
put();
121 for (
unsigned int i=0; i<v.size(); ++i) {
122 outFile << v[i] <<
"\n";
130 std::ifstream inFile( filename, std::ios::in);
132 std::cerr <<
" -- Engine state remains unchanged\n";
136 std::vector<unsigned long> v;
141 inFile.clear(std::ios::badbit | inFile.rdstate());
142 std::cerr <<
"\nJamesRandom state (vector) description improper."
143 <<
"\nrestoreStatus has failed."
144 <<
"\nInput stream is probably mispositioned now." << std::endl;
153 if (!inFile.bad() && !inFile.eof()) {
155 for (
int i=0; i<97; ++i)
157 inFile >> c; inFile >> cd; inFile >> cm;
167 std::cout << std::endl;
168 std::cout <<
"----- HepJamesRandom engine status -----" << std::endl;
169 std::cout <<
" Initial seed = " <<
theSeed << std::endl;
170 std::cout <<
" u[] = ";
171 for (
int i=0; i<97; ++i)
172 std::cout << u[i] <<
" ";
173 std::cout << std::endl;
174 std::cout <<
" c = " << c <<
", cd = " << cd <<
", cm = " << cm
176 std::cout <<
" i97 = " << i97 <<
", u[i97] = " << u[i97] << std::endl;
177 std::cout <<
" j97 = " << j97 <<
", u[j97] = " << u[j97] << std::endl;
178 std::cout <<
"----------------------------------------" << std::endl;
194 std::cout <<
"Seed for HepJamesRandom must be non-negative\n"
195 <<
"Seed value supplied was " << seed
196 <<
"\nUsing its absolute value instead\n";
200 long ij = seed/30082;
201 long kl = seed - 30082*ij;
202 long i = (ij/177) % 177 + 2;
203 long j = ij % 177 + 2;
204 long k = (kl/169) % 178 + 1;
209 for ( n = 1 ; n < 98 ; n++ ) {
212 for ( m = 1 ; m < 25 ; m++) {
213 mm = ( ( (i*j) % 179 ) * k ) % 179;
217 l = ( 53 * l + 1 ) % 169;
218 if ( (l*mm % 64 ) >= 32 )
224 c = 362436.0 / 16777216.0;
225 cd = 7654321.0 / 16777216.0;
226 cm = 16777213.0 / 16777216.0;
235 setSeed(seeds ? *seeds : 19780503L, 0);
244 uni = u[i97] - u[j97];
245 if ( uni < 0.0 ) uni++;
248 if (i97 == 0) i97 = 96;
251 if (j97 == 0) j97 = 96;
255 if (c < 0.0) c += cm;
258 if (uni < 0.0) uni += 1.0;
259 }
while ( uni <= 0.0 || uni >= 1.0 );
269 for (i=0; i<size; ++i) {
274HepJamesRandom::operator double() {
278HepJamesRandom::operator float() {
279 return float( flat() );
282HepJamesRandom::operator
unsigned int() {
283 return ((
unsigned int)(flat() * exponent_bit_32()) & 0xffffffff ) |
284 (((
unsigned int)( u[i97] * exponent_bit_32())>>16) & 0xff);
288 char beginMarker[] =
"JamesRandom-begin";
289 os << beginMarker <<
"\nUvec\n";
290 std::vector<unsigned long> v =
put();
291 for (
unsigned int i=0; i<v.size(); ++i) {
298 std::vector<unsigned long> v;
299 v.push_back (engineIDulong<HepJamesRandom>());
300 std::vector<unsigned long> t;
301 for (
int i=0; i<97; ++i) {
303 v.push_back(t[0]); v.push_back(t[1]);
306 v.push_back(t[0]); v.push_back(t[1]);
308 v.push_back(t[0]); v.push_back(t[1]);
310 v.push_back(t[0]); v.push_back(t[1]);
311 v.push_back(
static_cast<unsigned long>(j97));
317 char beginMarker [MarkerLen];
323 if (strcmp(beginMarker,
"JamesRandom-begin")) {
324 is.clear(std::ios::badbit | is.rdstate());
325 std::cerr <<
"\nInput stream mispositioned or"
326 <<
"\nJamesRandom state description missing or"
327 <<
"\nwrong engine type found." << std::endl;
334 return "JamesRandom-begin";
339 std::vector<unsigned long> v;
344 is.clear(std::ios::badbit | is.rdstate());
345 std::cerr <<
"\nJamesRandom state (vector) description improper."
346 <<
"\ngetState() has failed."
347 <<
"\nInput stream is probably mispositioned now." << std::endl;
359 char endMarker [MarkerLen];
360 for (
int i=0; i<97; ++i) {
363 is >> c; is >> cd; is >> cm;
368 if(strcmp(endMarker,
"JamesRandom-end")) {
369 is.clear(std::ios::badbit | is.rdstate());
370 std::cerr <<
"\nJamesRandom state description incomplete."
371 <<
"\nInput stream is probably mispositioned now." << std::endl;
382 if ( (v[0] & 0xffffffffUL) != engineIDulong<HepJamesRandom>()) {
384 "\nHepJamesRandom get:state vector has wrong ID word - state unchanged\n";
393 "\nHepJamesRandom get:state vector has wrong length - state unchanged\n";
396 std::vector<unsigned long> t(2);
397 for (
int i=0; i<97; ++i) {
398 t[0] = v[2*i+1]; t[1] = v[2*i+2];
#define CLHEP_ATOMIC_INT_TYPE
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)