55 const int maxIndex = 215;
65 long seedlist[2]={0,0};
80 long seedlist[2]={0,0};
83 int numEngines = numberOfEngines++;
84 int cycle = std::abs(
int(numEngines/maxIndex));
85 int curIndex = std::abs(
int(numEngines%maxIndex));
87 long mask = ((cycle & 0x007fffff) << 8);
89 seed = seedlist[0]^
mask;
102 long seedlist[2]={0,0};
105 int cycle = std::abs(
int(rowIndex/maxIndex));
106 int row = std::abs(
int(rowIndex%maxIndex));
107 int col = std::abs(
int(colIndex%2));
108 long mask = (( cycle & 0x000007ff ) << 20 );
110 seed = ( seedlist[
col] )^mask;
135 const int ecuyer_a = 53668;
136 const int ecuyer_b = 40014;
137 const int ecuyer_c = 12211;
138 const int ecuyer_d = 2147483563;
140 const int lux_levels[5] = {0,24,73,199,365};
142 long int_seed_table[24];
143 long next_seed =
seed;
151 if( (lux > 4)||(lux < 0) ){
155 nskip = lux_levels[3];
163 for(i = 0;i != 24;i++){
164 k_multiple = next_seed / ecuyer_a;
165 next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
166 - k_multiple * ecuyer_c ;
167 if(next_seed < 0)next_seed += ecuyer_d;
171 for(i = 0;i != 24;i++)
185 const int ecuyer_a = 53668;
186 const int ecuyer_b = 40014;
187 const int ecuyer_c = 12211;
188 const int ecuyer_d = 2147483563;
190 const int lux_levels[5] = {0,24,73,199,365};
192 long int_seed_table[24];
193 long k_multiple,next_seed;
210 if( (lux > 4)||(lux < 0) ){
214 nskip = lux_levels[3];
221 for( i = 0;(i != 24)&&(*seedptr != 0);i++){
227 next_seed = int_seed_table[i-1];
229 k_multiple = next_seed / ecuyer_a;
230 next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
231 - k_multiple * ecuyer_c ;
232 if(next_seed < 0)next_seed += ecuyer_d;
237 for(i = 0;i != 24;i++)
251 std::ofstream outFile( filename, std::ios::out ) ;
252 if (!outFile.bad()) {
254 std::vector<unsigned long> v =
put();
255 for (
unsigned int i=0; i<v.size(); ++i) {
256 outFile << v[i] <<
"\n";
265 std::cerr <<
" -- Engine state remains unchanged\n";
269 std::vector<unsigned long> v;
274 inFile.clear(std::ios::badbit | inFile.rdstate());
275 std::cerr <<
"\nRanluxEngine state (vector) description improper."
276 <<
"\nrestoreStatus has failed."
277 <<
"\nInput stream is probably mispositioned now." << std::endl;
286 if (!inFile.bad() && !inFile.eof()) {
288 for (
int i=0; i<24; ++i)
298 std::cout << std::endl;
299 std::cout <<
"--------- Ranlux engine status ---------" << std::endl;
300 std::cout <<
" Initial seed = " <<
theSeed << std::endl;
301 std::cout <<
" float_seed_table[] = ";
302 for (
int i=0; i<24; ++i)
304 std::cout << std::endl;
305 std::cout <<
" i_lag = " <<
i_lag <<
", j_lag = " <<
j_lag << std::endl;
306 std::cout <<
" carry = " <<
carry <<
", count24 = " <<
count24 << std::endl;
307 std::cout <<
" luxury = " <<
luxury <<
" nskip = " <<
nskip << std::endl;
308 std::cout <<
"----------------------------------------" << std::endl;
343 for( i = 0; i !=
nskip ; i++){
358 return (
double) next_random;
368 for (index=0; index<size; ++index) {
388 vect[index] = (double)next_random;
396 for( i = 0; i !=
nskip ; i++){
414 RanluxEngine::operator double() {
418 RanluxEngine::operator float() {
419 return float(
flat() );
422 RanluxEngine::operator
unsigned int() {
423 return ((
unsigned int)(
flat() * exponent_bit_32()) & 0xffffffff) |
424 (((
unsigned int)(float_seed_table[i_lag]*exponent_bit_32())>>16) & 0xff);
431 char beginMarker[] =
"RanluxEngine-begin";
432 os << beginMarker <<
"\nUvec\n";
433 std::vector<unsigned long> v =
put();
434 for (
unsigned int i=0; i<v.size(); ++i) {
441 std::vector<unsigned long> v;
442 v.push_back (engineIDulong<RanluxEngine>());
443 for (
int i=0; i<24; ++i) {
447 v.push_back(static_cast<unsigned long>(
i_lag));
448 v.push_back(static_cast<unsigned long>(
j_lag));
450 v.push_back(static_cast<unsigned long>(
count24));
451 v.push_back(static_cast<unsigned long>(
luxury));
452 v.push_back(static_cast<unsigned long>(
nskip));
464 if (strcmp(beginMarker,
"RanluxEngine-begin")) {
465 is.clear(std::ios::badbit | is.rdstate());
466 std::cerr <<
"\nInput stream mispositioned or"
467 <<
"\nRanluxEngine state description missing or"
468 <<
"\nwrong engine type found." << std::endl;
475 return "RanluxEngine-begin";
481 std::vector<unsigned long> v;
486 is.clear(std::ios::badbit | is.rdstate());
487 std::cerr <<
"\nRanluxEngine state (vector) description improper."
488 <<
"\ngetState() has failed."
489 <<
"\nInput stream is probably mispositioned now." << std::endl;
501 for (
int i=0; i<24; ++i) {
510 if (strcmp(endMarker,
"RanluxEngine-end")) {
511 is.clear(std::ios::badbit | is.rdstate());
512 std::cerr <<
"\nRanluxEngine state description incomplete."
513 <<
"\nInput stream is probably mispositioned now." << std::endl;
520 if ((v[0] & 0xffffffffUL) != engineIDulong<RanluxEngine>()) {
522 "\nRanluxEngine get:state vector has wrong ID word - state unchanged\n";
531 "\nRanluxEngine get:state vector has wrong length - state unchanged\n";
534 for (
int i=0; i<24; ++i) {
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
static std::string engineName()
void setSeed(long seed, int lux=3)
static const unsigned int VECTOR_STATE_SIZE
virtual std::istream & getState(std::istream &is)
void flatArray(const int size, double *vect)
float float_seed_table[24]
static double mantissa_bit_12()
static const int MarkerLen
static double mantissa_bit_24()
#define CLHEP_ATOMIC_INT_TYPE
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static const int int_modulus
void setSeeds(const long *seeds, int lux=3)
virtual std::istream & get(std::istream &is)
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
static constexpr double lux
static void getTheTableSeeds(long *seeds, int index)
std::vector< unsigned long > put() const
void saveStatus(const char filename[]="Ranlux.conf") const
static std::string beginTag()
void restoreStatus(const char filename[]="Ranlux.conf")