58 const int maxIndex = 215;
61static const int MarkerLen = 64;
68 long seedlist[2]={0,0};
83 long seedlist[2]={0,0};
86 int numEngines = numberOfEngines++;
87 int cycle = std::abs(
int(numEngines/maxIndex));
88 int curIndex = std::abs(
int(numEngines%maxIndex));
90 long mask = ((cycle & 0x007fffff) << 8);
92 seed = seedlist[0]^mask;
105 long seedlist[2]={0,0};
108 int cycle = std::abs(
int(rowIndex/maxIndex));
109 int row = std::abs(
int(rowIndex%maxIndex));
110 int col = std::abs(
int(colIndex%2));
111 long mask = (( cycle & 0x000007ff ) << 20 );
113 seed = ( seedlist[col] )^mask;
138 const int ecuyer_a = 53668;
139 const int ecuyer_b = 40014;
140 const int ecuyer_c = 12211;
141 const int ecuyer_d = 2147483563;
143 const int lux_levels[5] = {0,24,73,199,365};
145 long int_seed_table[24];
146 long next_seed = seed;
154 if( (lux > 4)||(lux < 0) ){
158 nskip = lux_levels[3];
162 nskip = lux_levels[luxury];
166 for(i = 0;i != 24;i++){
167 k_multiple = next_seed / ecuyer_a;
168 next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
169 - k_multiple * ecuyer_c ;
170 if(next_seed < 0)next_seed += ecuyer_d;
171 int_seed_table[i] = next_seed % int_modulus;
174 for(i = 0;i != 24;i++)
188 const int ecuyer_a = 53668;
189 const int ecuyer_b = 40014;
190 const int ecuyer_c = 12211;
191 const int ecuyer_d = 2147483563;
193 const int lux_levels[5] = {0,24,73,199,365};
195 long int_seed_table[24];
196 long k_multiple,next_seed;
213 if( (lux > 4)||(lux < 0) ){
217 nskip = lux_levels[3];
221 nskip = lux_levels[luxury];
224 for( i = 0;(i != 24)&&(*seedptr != 0);i++){
225 int_seed_table[i] = *seedptr % int_modulus;
230 next_seed = int_seed_table[i-1];
232 k_multiple = next_seed / ecuyer_a;
233 next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
234 - k_multiple * ecuyer_c ;
235 if(next_seed < 0)next_seed += ecuyer_d;
236 int_seed_table[i] = next_seed % int_modulus;
240 for(i = 0;i != 24;i++)
254 std::ofstream outFile( filename, std::ios::out ) ;
255 if (!outFile.bad()) {
257 std::vector<unsigned long> v =
put();
258 for (
unsigned int i=0; i<v.size(); ++i) {
259 outFile << v[i] <<
"\n";
266 std::ifstream inFile( filename, std::ios::in);
268 std::cerr <<
" -- Engine state remains unchanged\n";
272 std::vector<unsigned long> v;
277 inFile.clear(std::ios::badbit | inFile.rdstate());
278 std::cerr <<
"\nRanluxEngine state (vector) description improper."
279 <<
"\nrestoreStatus has failed."
280 <<
"\nInput stream is probably mispositioned now." << std::endl;
289 if (!inFile.bad() && !inFile.eof()) {
291 for (
int i=0; i<24; ++i)
292 inFile >> float_seed_table[i];
293 inFile >> i_lag; inFile >> j_lag;
294 inFile >> carry; inFile >> count24;
295 inFile >> luxury; inFile >> nskip;
301 std::cout << std::endl;
302 std::cout <<
"--------- Ranlux engine status ---------" << std::endl;
303 std::cout <<
" Initial seed = " <<
theSeed << std::endl;
304 std::cout <<
" float_seed_table[] = ";
305 for (
int i=0; i<24; ++i)
306 std::cout << float_seed_table[i] <<
" ";
307 std::cout << std::endl;
308 std::cout <<
" i_lag = " << i_lag <<
", j_lag = " << j_lag << std::endl;
309 std::cout <<
" carry = " << carry <<
", count24 = " << count24 << std::endl;
310 std::cout <<
" luxury = " << luxury <<
" nskip = " << nskip << std::endl;
311 std::cout <<
"----------------------------------------" << std::endl;
320 uni = float_seed_table[j_lag] - float_seed_table[i_lag] - carry;
328 float_seed_table[i_lag] = uni;
331 if(i_lag < 0) i_lag = 23;
332 if(j_lag < 0) j_lag = 23;
346 for( i = 0; i != nskip ; i++){
347 uni = float_seed_table[j_lag] - float_seed_table[i_lag] - carry;
354 float_seed_table[i_lag] = uni;
357 if(i_lag < 0)i_lag = 23;
358 if(j_lag < 0) j_lag = 23;
361 return (
double) next_random;
371 for (index=0; index<size; ++index) {
372 uni = float_seed_table[j_lag] - float_seed_table[i_lag] - carry;
380 float_seed_table[i_lag] = uni;
383 if(i_lag < 0) i_lag = 23;
384 if(j_lag < 0) j_lag = 23;
391 vect[index] = (double)next_random;
399 for( i = 0; i != nskip ; i++){
400 uni = float_seed_table[j_lag] - float_seed_table[i_lag] - carry;
407 float_seed_table[i_lag] = uni;
410 if(i_lag < 0)i_lag = 23;
411 if(j_lag < 0) j_lag = 23;
417RanluxEngine::operator double() {
421RanluxEngine::operator float() {
422 return float( flat() );
425RanluxEngine::operator
unsigned int() {
426 return ((
unsigned int)(flat() * exponent_bit_32()) & 0xffffffff) |
427 (((
unsigned int)(float_seed_table[i_lag]*exponent_bit_32())>>16) & 0xff);
434 char beginMarker[] =
"RanluxEngine-begin";
435 os << beginMarker <<
"\nUvec\n";
436 std::vector<unsigned long> v =
put();
437 for (
unsigned int i=0; i<v.size(); ++i) {
444 std::vector<unsigned long> v;
445 v.push_back (engineIDulong<RanluxEngine>());
446 for (
int i=0; i<24; ++i) {
450 v.push_back(
static_cast<unsigned long>(i_lag));
451 v.push_back(
static_cast<unsigned long>(j_lag));
453 v.push_back(
static_cast<unsigned long>(count24));
454 v.push_back(
static_cast<unsigned long>(luxury));
455 v.push_back(
static_cast<unsigned long>(nskip));
461 char beginMarker [MarkerLen];
467 if (strcmp(beginMarker,
"RanluxEngine-begin")) {
468 is.clear(std::ios::badbit | is.rdstate());
469 std::cerr <<
"\nInput stream mispositioned or"
470 <<
"\nRanluxEngine state description missing or"
471 <<
"\nwrong engine type found." << std::endl;
478 return "RanluxEngine-begin";
484 std::vector<unsigned long> v;
489 is.clear(std::ios::badbit | is.rdstate());
490 std::cerr <<
"\nRanluxEngine state (vector) description improper."
491 <<
"\ngetState() has failed."
492 <<
"\nInput stream is probably mispositioned now." << std::endl;
503 char endMarker [MarkerLen];
504 for (
int i=0; i<24; ++i) {
505 is >> float_seed_table[i];
507 is >> i_lag; is >> j_lag;
508 is >> carry; is >> count24;
509 is >> luxury; is >> nskip;
513 if (strcmp(endMarker,
"RanluxEngine-end")) {
514 is.clear(std::ios::badbit | is.rdstate());
515 std::cerr <<
"\nRanluxEngine state description incomplete."
516 <<
"\nInput stream is probably mispositioned now." << std::endl;
523 if ((v[0] & 0xffffffffUL) != engineIDulong<RanluxEngine>()) {
525 "\nRanluxEngine get:state vector has wrong ID word - state unchanged\n";
534 "\nRanluxEngine get:state vector has wrong length - state unchanged\n";
537 for (
int i=0; i<24; ++i) {
#define CLHEP_ATOMIC_INT_TYPE
static double mantissa_bit_12()
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
static double mantissa_bit_24()
static void getTheTableSeeds(long *seeds, int index)
static const unsigned int VECTOR_STATE_SIZE
void flatArray(const int size, double *vect)
virtual std::istream & getState(std::istream &is)
void saveStatus(const char filename[]="Ranlux.conf") const
std::vector< unsigned long > put() const
void setSeeds(const long *seeds, int lux=3)
static std::string beginTag()
virtual std::istream & get(std::istream &is)
void setSeed(long seed, int lux=3)
void restoreStatus(const char filename[]="Ranlux.conf")
static std::string engineName()
bool possibleKeywordInput(IS &is, const std::string &key, T &t)