83 tausworthe (1234567 + numEngines + 175321),
84 integerCong(69607 * tausworthe + 54329, numEngines)
92 tausworthe ((unsigned int)seed + 175321),
93 integerCong(69607 * tausworthe + 54329, 8043)
108 tausworthe (rowIndex + 1000 * colIndex + 85329),
109 integerCong(69607 * tausworthe + 54329, 1123)
126 for (
int i = 0; i < size; ++i) {
138 setSeed(seeds ? *seeds : 1234567, 0);
143 std::ofstream outFile(filename, std::ios::out);
144 if (!outFile.bad()) {
146 std::vector<unsigned long> v =
put();
147 for (
unsigned int i=0; i<v.size(); ++i) {
148 outFile << v[i] <<
"\n";
154 std::ifstream inFile(filename, std::ios::in);
156 std::cerr <<
" -- Engine state remains unchanged\n";
160 std::vector<unsigned long> v;
165 inFile.clear(std::ios::badbit | inFile.rdstate());
166 std::cerr <<
"\nDualRand state (vector) description improper."
167 <<
"\nrestoreStatus has failed."
168 <<
"\nInput stream is probably mispositioned now." << std::endl;
185 int pr=std::cout.precision(20);
186 std::cout << std::endl;
187 std::cout <<
"-------- DualRand engine status ---------"
189 std::cout <<
"Initial seed = " <<
theSeed << std::endl;
190 std::cout <<
"Tausworthe generator = " << std::endl;
192 std::cout <<
"\nIntegerCong generator = " << std::endl;
194 std::cout << std::endl <<
"-----------------------------------------"
196 std::cout.precision(pr);
199DualRand::operator double() {
203DualRand::operator float() {
204 return (
float) ( (integerCong ^ tausworthe) * twoToMinus_32()
205 + nearlyTwoToMinus_54() );
209DualRand::operator
unsigned int() {
210 return (integerCong ^ tausworthe) & 0xffffffff;
214 char beginMarker[] =
"DualRand-begin";
215 os << beginMarker <<
"\nUvec\n";
216 std::vector<unsigned long> v =
put();
217 for (
unsigned int i=0; i<v.size(); ++i) {
224 std::vector<unsigned long> v;
225 v.push_back (engineIDulong<DualRand>());
238 if (strcmp(beginMarker,
"DualRand-begin")) {
239 is.clear(std::ios::badbit | is.rdstate());
240 std::cerr <<
"\nInput mispositioned or"
241 <<
"\nDualRand state description missing or"
242 <<
"\nwrong engine type found." << std::endl;
249 return "DualRand-begin";
254 std::vector<unsigned long> v;
259 is.clear(std::ios::badbit | is.rdstate());
260 std::cerr <<
"\nDualRand state (vector) description improper."
261 <<
"\ngetState() has failed."
262 <<
"\nInput stream is probably mispositioned now." << std::endl;
279 if (strcmp(endMarker,
"DualRand-end")) {
280 is.clear(std::ios::badbit | is.rdstate());
281 std::cerr <<
"DualRand state description incomplete."
282 <<
"\nInput stream is probably mispositioned now." << std::endl;
289 if ((v[0] & 0xffffffffUL) != engineIDulong<DualRand>()) {
291 "\nDualRand get:state vector has wrong ID word - state unchanged\n";
295 std::cerr <<
"\nDualRand get:state vector has wrong size: "
296 << v.size() <<
" - state unchanged\n";
303 std::vector<unsigned long>::const_iterator iv = v.begin()+1;
308 "\nDualRand get:state vector has wrong size: " << v.size()
309 <<
"\n Apparently " << iv-v.begin() <<
" words were consumed\n";
324 for (wordIndex = 1; wordIndex < 4; ++wordIndex) {
325 words[wordIndex] = 69607 * words[wordIndex-1] + 54329;
329DualRand::Tausworthe::operator
unsigned int() {
375 if (wordIndex <= 0) {
376 for (wordIndex = 0; wordIndex < 4; ++wordIndex) {
377 words[wordIndex] = ( (words[(wordIndex+1) & 3] << 1 ) |
378 (words[wordIndex] >> 31) )
379 ^ ( (words[(wordIndex+1) & 3] << 31) |
380 (words[wordIndex] >> 1) );
383 return words[--wordIndex] & 0xffffffff;
387 char beginMarker[] =
"Tausworthe-begin";
388 char endMarker[] =
"Tausworthe-end";
390 int pr=os.precision(20);
391 os <<
" " << beginMarker <<
" ";
392 for (
int i = 0; i < 4; ++i) {
393 os << words[i] <<
" ";
396 os <<
" " << endMarker <<
" ";
402 for (
int i = 0; i < 4; ++i) {
403 v.push_back(
static_cast<unsigned long>(words[i]));
405 v.push_back(
static_cast<unsigned long>(wordIndex));
417 if (strcmp(beginMarker,
"Tausworthe-begin")) {
418 is.clear(std::ios::badbit | is.rdstate());
419 std::cerr <<
"\nInput mispositioned or"
420 <<
"\nTausworthe state description missing or"
421 <<
"\nwrong engine type found." << std::endl;
423 for (
int i = 0; i < 4; ++i) {
430 if (strcmp(endMarker,
"Tausworthe-end")) {
431 is.clear(std::ios::badbit | is.rdstate());
432 std::cerr <<
"\nTausworthe state description incomplete."
433 <<
"\nInput stream is probably mispositioned now." << std::endl;
439 for (
int i = 0; i < 4; ++i) {
447: state((unsigned int)3758656018U),
455 multiplier(65536 + 1024 + 5 + (8 * 1017 * streamNumber)),
473DualRand::IntegerCong::operator
unsigned int() {
474 return state = (state * multiplier + addend) & 0xffffffff;
478 char beginMarker[] =
"IntegerCong-begin";
479 char endMarker[] =
"IntegerCong-end";
481 int pr=os.precision(20);
482 os <<
" " << beginMarker <<
" ";
483 os << state <<
" " << multiplier <<
" " << addend;
484 os <<
" " << endMarker <<
" ";
490 v.push_back(
static_cast<unsigned long>(state));
491 v.push_back(
static_cast<unsigned long>(multiplier));
492 v.push_back(
static_cast<unsigned long>(addend));
504 if (strcmp(beginMarker,
"IntegerCong-begin")) {
505 is.clear(std::ios::badbit | is.rdstate());
506 std::cerr <<
"\nInput mispositioned or"
507 <<
"\nIntegerCong state description missing or"
508 <<
"\nwrong engine type found." << std::endl;
510 is >> state >> multiplier >> addend;
514 if (strcmp(endMarker,
"IntegerCong-end")) {
515 is.clear(std::ios::badbit | is.rdstate());
516 std::cerr <<
"\nIntegerCong state description incomplete."
517 <<
"\nInput stream is probably mispositioned now." << std::endl;
#define CLHEP_ATOMIC_INT_TYPE
void put(std::ostream &os) const
void get(std::istream &is)
void put(std::ostream &os) const
void get(std::istream &is)
void setSeeds(const long *seeds, int)
std::vector< unsigned long > put() const
static const unsigned int VECTOR_STATE_SIZE
void restoreStatus(const char filename[]="DualRand.conf")
void setSeed(long seed, int)
void saveStatus(const char filename[]="DualRand.conf") const
void flatArray(const int size, double *vect)
virtual std::istream & get(std::istream &is)
static std::string engineName()
virtual std::istream & getState(std::istream &is)
static std::string beginTag()
static double twoToMinus_32()
static double twoToMinus_53()
static double nearlyTwoToMinus_54()
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
CLHEP_ATOMIC_INT_TYPE numberOfEngines(0)
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
static const int MarkerLen