78 numEngines(numberOfEngines++),
79 tausworthe (1234567 + numEngines + 175321),
80 integerCong(69607 * tausworthe + 54329, numEngines)
88 tausworthe ((unsigned
int)seed + 175321),
89 integerCong(69607 * tausworthe + 54329, 8043)
104 tausworthe (rowIndex + 1000 * colIndex + 85329),
105 integerCong(69607 * tausworthe + 54329, 1123)
122 for (
int i = 0; i < size; ++i) {
134 setSeed(seeds ? *seeds : 1234567, 0);
139 std::ofstream outFile(filename, std::ios::out);
140 if (!outFile.bad()) {
142 std::vector<unsigned long>
v =
put();
143 for (
unsigned int i=0; i<v.size(); ++i) {
144 outFile << v[i] <<
"\n";
152 std::cerr <<
" -- Engine state remains unchanged\n";
156 std::vector<unsigned long>
v;
161 inFile.clear(std::ios::badbit | inFile.rdstate());
162 std::cerr <<
"\nDualRand state (vector) description improper."
163 <<
"\nrestoreStatus has failed."
164 <<
"\nInput stream is probably mispositioned now." << std::endl;
181 int pr=std::cout.precision(20);
182 std::cout << std::endl;
183 std::cout <<
"-------- DualRand engine status ---------"
185 std::cout <<
"Initial seed = " <<
theSeed << std::endl;
186 std::cout <<
"Tausworthe generator = " << std::endl;
188 std::cout <<
"\nIntegerCong generator = " << std::endl;
190 std::cout << std::endl <<
"-----------------------------------------"
192 std::cout.precision(pr);
195 DualRand::operator double() {
199 DualRand::operator float() {
200 return (
float) ( (integerCong ^ tausworthe) * twoToMinus_32()
201 + nearlyTwoToMinus_54() );
205 DualRand::operator
unsigned int() {
206 return (integerCong ^ tausworthe) & 0xffffffff;
210 char beginMarker[] =
"DualRand-begin";
211 os << beginMarker <<
"\nUvec\n";
212 std::vector<unsigned long>
v =
put();
213 for (
unsigned int i=0; i<v.size(); ++i) {
220 std::vector<unsigned long>
v;
221 v.push_back (engineIDulong<DualRand>());
234 if (strcmp(beginMarker,
"DualRand-begin")) {
235 is.clear(std::ios::badbit | is.rdstate());
236 std::cerr <<
"\nInput mispositioned or"
237 <<
"\nDualRand state description missing or"
238 <<
"\nwrong engine type found." << std::endl;
245 return "DualRand-begin";
250 std::vector<unsigned long>
v;
255 is.clear(std::ios::badbit | is.rdstate());
256 std::cerr <<
"\nDualRand state (vector) description improper."
257 <<
"\ngetState() has failed."
258 <<
"\nInput stream is probably mispositioned now." << std::endl;
275 if (strcmp(endMarker,
"DualRand-end")) {
276 is.clear(std::ios::badbit | is.rdstate());
277 std::cerr <<
"DualRand state description incomplete."
278 <<
"\nInput stream is probably mispositioned now." << std::endl;
285 if ((v[0] & 0xffffffffUL) != engineIDulong<DualRand>()) {
287 "\nDualRand get:state vector has wrong ID word - state unchanged\n";
291 std::cerr <<
"\nDualRand get:state vector has wrong size: "
292 << v.size() <<
" - state unchanged\n";
299 std::vector<unsigned long>::const_iterator iv = v.begin()+1;
304 "\nDualRand get:state vector has wrong size: " << v.size()
305 <<
"\n Apparently " << iv-v.begin() <<
" words were consumed\n";
320 for (wordIndex = 1; wordIndex < 4; ++wordIndex) {
321 words[wordIndex] = 69607 * words[wordIndex-1] + 54329;
325 DualRand::Tausworthe::operator
unsigned int() {
371 if (wordIndex <= 0) {
372 for (wordIndex = 0; wordIndex < 4; ++wordIndex) {
373 words[wordIndex] = ( (words[(wordIndex+1) & 3] << 1 ) |
374 (words[wordIndex] >> 31) )
375 ^ ( (words[(wordIndex+1) & 3] << 31) |
376 (words[wordIndex] >> 1) );
379 return words[--wordIndex] & 0xffffffff;
383 char beginMarker[] =
"Tausworthe-begin";
384 char endMarker[] =
"Tausworthe-end";
386 int pr=os.precision(20);
387 os <<
" " << beginMarker <<
" ";
388 for (
int i = 0; i < 4; ++i) {
389 os << words[i] <<
" ";
392 os <<
" " << endMarker <<
" ";
398 for (
int i = 0; i < 4; ++i) {
399 v.push_back(static_cast<unsigned long>(words[i]));
401 v.push_back(static_cast<unsigned long>(wordIndex));
413 if (strcmp(beginMarker,
"Tausworthe-begin")) {
414 is.clear(std::ios::badbit | is.rdstate());
415 std::cerr <<
"\nInput mispositioned or"
416 <<
"\nTausworthe state description missing or"
417 <<
"\nwrong engine type found." << std::endl;
419 for (
int i = 0; i < 4; ++i) {
426 if (strcmp(endMarker,
"Tausworthe-end")) {
427 is.clear(std::ios::badbit | is.rdstate());
428 std::cerr <<
"\nTausworthe state description incomplete."
429 <<
"\nInput stream is probably mispositioned now." << std::endl;
435 for (
int i = 0; i < 4; ++i) {
443 : state((unsigned
int)3758656018U),
451 multiplier(65536 + 1024 + 5 + (8 * 1017 * streamNumber)),
469 DualRand::IntegerCong::operator
unsigned int() {
470 return state = (state * multiplier + addend) & 0xffffffff;
474 char beginMarker[] =
"IntegerCong-begin";
475 char endMarker[] =
"IntegerCong-end";
477 int pr=os.precision(20);
478 os <<
" " << beginMarker <<
" ";
479 os << state <<
" " << multiplier <<
" " << addend;
480 os <<
" " << endMarker <<
" ";
486 v.push_back(static_cast<unsigned long>(state));
487 v.push_back(static_cast<unsigned long>(multiplier));
488 v.push_back(static_cast<unsigned long>(addend));
500 if (strcmp(beginMarker,
"IntegerCong-begin")) {
501 is.clear(std::ios::badbit | is.rdstate());
502 std::cerr <<
"\nInput mispositioned or"
503 <<
"\nIntegerCong state description missing or"
504 <<
"\nwrong engine type found." << std::endl;
506 is >> state >> multiplier >> addend;
510 if (strcmp(endMarker,
"IntegerCong-end")) {
511 is.clear(std::ios::badbit | is.rdstate());
512 std::cerr <<
"\nIntegerCong state description incomplete."
513 <<
"\nInput stream is probably mispositioned now." << std::endl;