49static const int MarkerLen = 64;
54int RanluxEngine::numEngines = 0;
57int RanluxEngine::maxIndex = 215;
62 long seedlist[2]={0,0};
77 long seedlist[2]={0,0};
80 int cycle = std::abs(
int(numEngines/maxIndex));
81 int curIndex = std::abs(
int(numEngines%maxIndex));
83 long mask = ((cycle & 0x007fffff) << 8);
85 seed = seedlist[0]^mask;
98 long seedlist[2]={0,0};
101 int cycle = std::abs(
int(rowIndex/maxIndex));
102 int row = std::abs(
int(rowIndex%maxIndex));
103 int col = std::abs(
int(colIndex%2));
104 long mask = (( cycle & 0x000007ff ) << 20 );
106 seed = ( seedlist[col] )^mask;
131 const int ecuyer_a = 53668;
132 const int ecuyer_b = 40014;
133 const int ecuyer_c = 12211;
134 const int ecuyer_d = 2147483563;
136 const int lux_levels[5] = {0,24,73,199,365};
138 long int_seed_table[24];
139 long next_seed = seed;
147 if( (lux > 4)||(lux < 0) ){
151 nskip = lux_levels[3];
155 nskip = lux_levels[luxury];
159 for(i = 0;i != 24;i++){
160 k_multiple = next_seed / ecuyer_a;
161 next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
162 - k_multiple * ecuyer_c ;
163 if(next_seed < 0)next_seed += ecuyer_d;
164 int_seed_table[i] = next_seed % int_modulus;
167 for(i = 0;i != 24;i++)
181 const int ecuyer_a = 53668;
182 const int ecuyer_b = 40014;
183 const int ecuyer_c = 12211;
184 const int ecuyer_d = 2147483563;
186 const int lux_levels[5] = {0,24,73,199,365};
188 long int_seed_table[24];
189 long k_multiple,next_seed;
206 if( (lux > 4)||(lux < 0) ){
210 nskip = lux_levels[3];
214 nskip = lux_levels[luxury];
217 for( i = 0;(i != 24)&&(*seedptr != 0);i++){
218 int_seed_table[i] = *seedptr % int_modulus;
223 next_seed = int_seed_table[i-1];
225 k_multiple = next_seed / ecuyer_a;
226 next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
227 - k_multiple * ecuyer_c ;
228 if(next_seed < 0)next_seed += ecuyer_d;
229 int_seed_table[i] = next_seed % int_modulus;
233 for(i = 0;i != 24;i++)
247 std::ofstream outFile( filename, std::ios::out ) ;
248 if (!outFile.bad()) {
250 std::vector<unsigned long> v =
put();
251 for (
unsigned int i=0; i<v.size(); ++i) {
252 outFile << v[i] <<
"\n";
259 std::ifstream inFile( filename, std::ios::in);
261 std::cerr <<
" -- Engine state remains unchanged\n";
265 std::vector<unsigned long> v;
270 inFile.clear(std::ios::badbit | inFile.rdstate());
271 std::cerr <<
"\nRanluxEngine state (vector) description improper."
272 <<
"\nrestoreStatus has failed."
273 <<
"\nInput stream is probably mispositioned now." << std::endl;
282 if (!inFile.bad() && !inFile.eof()) {
284 for (
int i=0; i<24; ++i)
285 inFile >> float_seed_table[i];
286 inFile >> i_lag; inFile >> j_lag;
287 inFile >> carry; inFile >> count24;
288 inFile >> luxury; inFile >> nskip;
294 std::cout << std::endl;
295 std::cout <<
"--------- Ranlux engine status ---------" << std::endl;
296 std::cout <<
" Initial seed = " <<
theSeed << std::endl;
297 std::cout <<
" float_seed_table[] = ";
298 for (
int i=0; i<24; ++i)
299 std::cout << float_seed_table[i] <<
" ";
300 std::cout << std::endl;
301 std::cout <<
" i_lag = " << i_lag <<
", j_lag = " << j_lag << std::endl;
302 std::cout <<
" carry = " << carry <<
", count24 = " << count24 << std::endl;
303 std::cout <<
" luxury = " << luxury <<
" nskip = " << nskip << std::endl;
304 std::cout <<
"----------------------------------------" << std::endl;
313 uni = float_seed_table[j_lag] - float_seed_table[i_lag] - carry;
321 float_seed_table[i_lag] = uni;
324 if(i_lag < 0) i_lag = 23;
325 if(j_lag < 0) j_lag = 23;
339 for( i = 0; i != nskip ; i++){
340 uni = float_seed_table[j_lag] - float_seed_table[i_lag] - carry;
347 float_seed_table[i_lag] = uni;
350 if(i_lag < 0)i_lag = 23;
351 if(j_lag < 0) j_lag = 23;
354 return (
double) next_random;
364 for (index=0; index<size; ++index) {
365 uni = float_seed_table[j_lag] - float_seed_table[i_lag] - carry;
373 float_seed_table[i_lag] = uni;
376 if(i_lag < 0) i_lag = 23;
377 if(j_lag < 0) j_lag = 23;
384 vect[index] = (double)next_random;
392 for( i = 0; i != nskip ; i++){
393 uni = float_seed_table[j_lag] - float_seed_table[i_lag] - carry;
400 float_seed_table[i_lag] = uni;
403 if(i_lag < 0)i_lag = 23;
404 if(j_lag < 0) j_lag = 23;
410RanluxEngine::operator
unsigned int() {
411 return ((
unsigned int)(flat() * exponent_bit_32()) & 0xffffffff) |
412 (((
unsigned int)(float_seed_table[i_lag]*exponent_bit_32())>>16) & 0xff);
419 char beginMarker[] =
"RanluxEngine-begin";
420 os << beginMarker <<
"\nUvec\n";
421 std::vector<unsigned long> v =
put();
422 for (
unsigned int i=0; i<v.size(); ++i) {
429 std::vector<unsigned long> v;
430 v.push_back (engineIDulong<RanluxEngine>());
431 for (
int i=0; i<24; ++i) {
435 v.push_back(
static_cast<unsigned long>(i_lag));
436 v.push_back(
static_cast<unsigned long>(j_lag));
438 v.push_back(
static_cast<unsigned long>(count24));
439 v.push_back(
static_cast<unsigned long>(luxury));
440 v.push_back(
static_cast<unsigned long>(nskip));
446 char beginMarker [MarkerLen];
452 if (strcmp(beginMarker,
"RanluxEngine-begin")) {
453 is.clear(std::ios::badbit | is.rdstate());
454 std::cerr <<
"\nInput stream mispositioned or"
455 <<
"\nRanluxEngine state description missing or"
456 <<
"\nwrong engine type found." << std::endl;
463 return "RanluxEngine-begin";
469 std::vector<unsigned long> v;
474 is.clear(std::ios::badbit | is.rdstate());
475 std::cerr <<
"\nRanluxEngine state (vector) description improper."
476 <<
"\ngetState() has failed."
477 <<
"\nInput stream is probably mispositioned now." << std::endl;
488 char endMarker [MarkerLen];
489 for (
int i=0; i<24; ++i) {
490 is >> float_seed_table[i];
492 is >> i_lag; is >> j_lag;
493 is >> carry; is >> count24;
494 is >> luxury; is >> nskip;
498 if (strcmp(endMarker,
"RanluxEngine-end")) {
499 is.clear(std::ios::badbit | is.rdstate());
500 std::cerr <<
"\nRanluxEngine state description incomplete."
501 <<
"\nInput stream is probably mispositioned now." << std::endl;
508 if ((v[0] & 0xffffffffUL) != engineIDulong<RanluxEngine>()) {
510 "\nRanluxEngine get:state vector has wrong ID word - state unchanged\n";
519 "\nRanluxEngine get:state vector has wrong length - state unchanged\n";
522 for (
int i=0; i<24; ++i) {
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)