56 const int maxIndex = 215;
76 int numEngines = numberOfEngines++;
77 int cycle = std::abs(
int(numEngines/maxIndex));
78 int curIndex = std::abs(
int(numEngines%maxIndex));
80 long mask = ((cycle & 0x007fffff) << 8);
93 int cycle = std::abs(
int(rowIndex/maxIndex));
94 int row = std::abs(
int(rowIndex%maxIndex));
95 int col = std::abs(
int(colIndex%2));
96 long mask = ((cycle & 0x000007ff) << 20);
98 seed = (seeds[col])^mask;
113 std::ofstream outFile( filename, std::ios::out ) ;
115 if (!outFile.bad()) {
117 std::vector<unsigned long> v =
put();
118 for (
unsigned int i=0; i<v.size(); ++i) {
119 outFile << v[i] <<
"\n";
127 std::ifstream inFile( filename, std::ios::in);
129 std::cerr <<
" -- Engine state remains unchanged\n";
133 std::vector<unsigned long> v;
138 inFile.clear(std::ios::badbit | inFile.rdstate());
139 std::cerr <<
"\nJamesRandom state (vector) description improper."
140 <<
"\nrestoreStatus has failed."
141 <<
"\nInput stream is probably mispositioned now." << std::endl;
150 if (!inFile.bad() && !inFile.eof()) {
152 for (
int i=0; i<97; ++i)
154 inFile >> c; inFile >> cd; inFile >> cm;
164 std::cout << std::endl;
165 std::cout <<
"----- HepJamesRandom engine status -----" << std::endl;
166 std::cout <<
" Initial seed = " <<
theSeed << std::endl;
167 std::cout <<
" u[] = ";
168 for (
int i=0; i<97; ++i)
169 std::cout << u[i] <<
" ";
170 std::cout << std::endl;
171 std::cout <<
" c = " << c <<
", cd = " << cd <<
", cm = " << cm
173 std::cout <<
" i97 = " << i97 <<
", u[i97] = " << u[i97] << std::endl;
174 std::cout <<
" j97 = " << j97 <<
", u[j97] = " << u[j97] << std::endl;
175 std::cout <<
"----------------------------------------" << std::endl;
191 std::cout <<
"Seed for HepJamesRandom must be non-negative\n"
192 <<
"Seed value supplied was " << seed
193 <<
"\nUsing its absolute value instead\n";
197 long ij = seed/30082;
198 long kl = seed - 30082*ij;
199 long i = (ij/177) % 177 + 2;
200 long j = ij % 177 + 2;
201 long k = (kl/169) % 178 + 1;
206 for ( n = 1 ; n < 98 ; n++ ) {
209 for ( m = 1 ; m < 25 ; m++) {
210 mm = ( ( (i*j) % 179 ) * k ) % 179;
214 l = ( 53 * l + 1 ) % 169;
215 if ( (l*mm % 64 ) >= 32 )
221 c = 362436.0 / 16777216.0;
222 cd = 7654321.0 / 16777216.0;
223 cm = 16777213.0 / 16777216.0;
232 setSeed(seeds ? *seeds : 19780503
L, 0);
241 uni = u[i97] - u[j97];
242 if ( uni < 0.0 ) uni++;
245 if (i97 == 0) i97 = 96;
248 if (j97 == 0) j97 = 96;
252 if (c < 0.0) c += cm;
255 if (uni < 0.0) uni += 1.0;
256 }
while ( uni <= 0.0 || uni >= 1.0 );
266 for (i=0; i<size; ++i) {
271 HepJamesRandom::operator
unsigned int() {
272 return ((
unsigned int)(
flat() * exponent_bit_32()) & 0xffffffff ) |
273 (((
unsigned int)( u[i97] * exponent_bit_32())>>16) & 0xff);
277 char beginMarker[] =
"JamesRandom-begin";
278 os << beginMarker <<
"\nUvec\n";
279 std::vector<unsigned long> v =
put();
280 for (
unsigned int i=0; i<v.size(); ++i) {
287 std::vector<unsigned long> v;
288 v.push_back (engineIDulong<HepJamesRandom>());
289 std::vector<unsigned long> t;
290 for (
int i=0; i<97; ++i) {
292 v.push_back(t[0]); v.push_back(t[1]);
295 v.push_back(t[0]); v.push_back(t[1]);
297 v.push_back(t[0]); v.push_back(t[1]);
299 v.push_back(t[0]); v.push_back(t[1]);
300 v.push_back(static_cast<unsigned long>(j97));
312 if (strcmp(beginMarker,
"JamesRandom-begin")) {
313 is.clear(std::ios::badbit | is.rdstate());
314 std::cerr <<
"\nInput stream mispositioned or"
315 <<
"\nJamesRandom state description missing or"
316 <<
"\nwrong engine type found." << std::endl;
323 return "JamesRandom-begin";
328 std::vector<unsigned long> v;
333 is.clear(std::ios::badbit | is.rdstate());
334 std::cerr <<
"\nJamesRandom state (vector) description improper."
335 <<
"\ngetState() has failed."
336 <<
"\nInput stream is probably mispositioned now." << std::endl;
349 for (
int i=0; i<97; ++i) {
352 is >> c; is >> cd; is >> cm;
357 if(strcmp(endMarker,
"JamesRandom-end")) {
358 is.clear(std::ios::badbit | is.rdstate());
359 std::cerr <<
"\nJamesRandom state description incomplete."
360 <<
"\nInput stream is probably mispositioned now." << std::endl;
371 if ( (v[0] & 0xffffffffUL) != engineIDulong<HepJamesRandom>()) {
373 "\nHepJamesRandom get:state vector has wrong ID word - state unchanged\n";
382 "\nHepJamesRandom get:state vector has wrong length - state unchanged\n";
385 std::vector<unsigned long> t(2);
386 for (
int i=0; i<97; ++i) {
387 t[0] = v[2*i+1]; t[1] = v[2*i+2];
static constexpr double m
static const int MarkerLen
void saveStatus(const char filename[]="JamesRand.conf") const
static std::string beginTag()
static std::string engineName()
virtual std::istream & getState(std::istream &is)
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
virtual std::istream & get(std::istream &is)
void setSeed(long seed, int dum=0)
std::vector< unsigned long > put() const
static constexpr double mm
#define CLHEP_ATOMIC_INT_TYPE
virtual ~HepJamesRandom()
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
void setSeeds(const long *seeds, int dum=0)
static constexpr double s
static std::vector< unsigned long > dto2longs(double d)
void flatArray(const int size, double *vect)
static const unsigned int VECTOR_STATE_SIZE
void restoreStatus(const char filename[]="JamesRand.conf")
static constexpr double L
static void getTheTableSeeds(long *seeds, int index)
static double longs2double(const std::vector< unsigned long > &v)