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";
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);
242 if ( uni < 0.0 ) uni++;
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 double() {
275 HepJamesRandom::operator float() {
276 return float(
flat() );
279 HepJamesRandom::operator
unsigned int() {
280 return ((
unsigned int)(
flat() * exponent_bit_32()) & 0xffffffff ) |
281 (((
unsigned int)( u[i97] * exponent_bit_32())>>16) & 0xff);
285 char beginMarker[] =
"JamesRandom-begin";
286 os << beginMarker <<
"\nUvec\n";
287 std::vector<unsigned long> v =
put();
288 for (
unsigned int i=0; i<v.size(); ++i) {
295 std::vector<unsigned long> v;
296 v.push_back (engineIDulong<HepJamesRandom>());
297 std::vector<unsigned long> t;
298 for (
int i=0; i<97; ++i) {
300 v.push_back(t[0]); v.push_back(t[1]);
303 v.push_back(t[0]); v.push_back(t[1]);
305 v.push_back(t[0]); v.push_back(t[1]);
307 v.push_back(t[0]); v.push_back(t[1]);
308 v.push_back(static_cast<unsigned long>(
j97));
320 if (strcmp(beginMarker,
"JamesRandom-begin")) {
321 is.clear(std::ios::badbit | is.rdstate());
322 std::cerr <<
"\nInput stream mispositioned or"
323 <<
"\nJamesRandom state description missing or"
324 <<
"\nwrong engine type found." << std::endl;
331 return "JamesRandom-begin";
336 std::vector<unsigned long> v;
341 is.clear(std::ios::badbit | is.rdstate());
342 std::cerr <<
"\nJamesRandom state (vector) description improper."
343 <<
"\ngetState() has failed."
344 <<
"\nInput stream is probably mispositioned now." << std::endl;
357 for (
int i=0; i<97; ++i) {
360 is >>
c; is >>
cd; is >>
cm;
365 if(strcmp(endMarker,
"JamesRandom-end")) {
366 is.clear(std::ios::badbit | is.rdstate());
367 std::cerr <<
"\nJamesRandom state description incomplete."
368 <<
"\nInput stream is probably mispositioned now." << std::endl;
379 if ( (v[0] & 0xffffffffUL) != engineIDulong<HepJamesRandom>()) {
381 "\nHepJamesRandom get:state vector has wrong ID word - state unchanged\n";
390 "\nHepJamesRandom get:state vector has wrong length - state unchanged\n";
393 std::vector<unsigned long> t(2);
394 for (
int i=0; i<97; ++i) {
395 t[0] = v[2*i+1]; t[1] = v[2*i+2];
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
void setSeed(long seed, int dum=0)
void saveStatus(const char filename[]="JamesRand.conf") const
static std::string beginTag()
void flatArray(const int size, double *vect)
std::vector< unsigned long > put() const
static const unsigned int VECTOR_STATE_SIZE
static double longs2double(const std::vector< unsigned long > &v)
virtual ~HepJamesRandom()
static const int MarkerLen
static constexpr double L
#define CLHEP_ATOMIC_INT_TYPE
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
void setSeeds(const long *seeds, int dum=0)
static constexpr double s
virtual std::istream & getState(std::istream &is)
static std::vector< unsigned long > dto2longs(double d)
static constexpr double m
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)
static constexpr double mm
static std::string engineName()
void restoreStatus(const char filename[]="JamesRand.conf")
virtual std::istream & get(std::istream &is)