68 long seedlist[2]={0,0};
83 long seedlist[2]={0,0};
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};
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];
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;
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];
224 for( i = 0;(i != 24)&&(*seedptr != 0);i++){
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;
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)
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)
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;
346 for( i = 0; i !=
nskip ; i++){
361 return (
double) next_random;
371 for (index=0; index<size; ++index) {
391 vect[index] = (double)next_random;
399 for( i = 0; i !=
nskip ; i++){
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));
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;
504 for (
int i=0; i<24; ++i) {
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)
static const int int_modulus
void setSeeds(const long *seeds, int lxr=3)
virtual std::istream & getState(std::istream &is)
void saveStatus(const char filename[]="Ranlux.conf") const
std::vector< unsigned long > put() const
static std::string beginTag()
virtual std::istream & get(std::istream &is)
void restoreStatus(const char filename[]="Ranlux.conf")
static std::string engineName()
void setSeed(long seed, int lxr=3)
float float_seed_table[24]
CLHEP_ATOMIC_INT_TYPE numberOfEngines(0)
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
static const int MarkerLen
static constexpr double lux