72 const int maxIndex = 215;
81 template< std::size_t
n,
82 bool = n < std::size_t(std::numeric_limits<unsigned long>::digits) >
83 struct do_right_shift;
84 template< std::
size_t n >
85 struct do_right_shift<n,true>
87 unsigned long operator()(
unsigned long value) {
return value >>
n; }
89 template< std::
size_t n >
95 template< std::
size_t nbits >
97 {
return do_right_shift<nbits>()(value); }
108 int numEngines = numberOfEngines++;
109 int cycle =
std::abs(
int(numEngines/maxIndex));
110 int curIndex =
std::abs(
int(numEngines%maxIndex));
112 long mask = ((cycle & 0x007fffff) << 8);
128 long seedlist[2]={
seed,0};
138 int cycle =
std::abs(
int(rowIndex/maxIndex));
139 int row =
std::abs(
int(rowIndex%maxIndex));
140 long mask = (( cycle & 0x000007ff ) << 20 );
219 for ( m = 0, nr = 11, ns = 4; m <
endIters; ++
m, --nr ) {
235 for (m=0; m<12; m++) {
240 for (m=11; m>=0; --
m) {
282 for ( k = dozens; k > 0; --
k ) {
293 y3 = randoms[ 2] - randoms[ 9];
300 y1 = randoms[ 1] - randoms[ 8];
307 y2 = randoms[ 0] - randoms[ 7];
314 y3 = randoms[11] - randoms[ 6];
321 y1 = randoms[10] - randoms[ 5];
328 y2 = randoms[ 9] - randoms[ 4];
335 y3 = randoms[ 8] - randoms[ 3];
342 y1 = randoms[ 7] - randoms[ 2];
349 y2 = randoms[ 6] - randoms[ 1];
356 y3 = randoms[ 5] - randoms[ 0];
374 for(
int i=0; i < size; ++i ) {
387 const int ecuyer_a(53668);
388 const int ecuyer_b(40014);
389 const int ecuyer_c(12211);
390 const int ecuyer_d(2147483563);
392 const int lux_levels[3] = {109, 202, 397};
395 if( (lux > 2)||(lux < 0) ){
396 pDiscard = (lux >= 12) ? (lux-12) : lux_levels[1];
404 long next_seed =
seed;
407 next_seed &= 0xffffffff;
408 while( next_seed >= ecuyer_d ) {
409 next_seed -= ecuyer_d;
412 for(i = 0;i != 24;i++){
413 k_multiple = next_seed / ecuyer_a;
414 next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
415 - k_multiple * ecuyer_c;
417 next_seed += ecuyer_d;
419 next_seed &= 0xffffffff;
420 init_table[i] = next_seed;
423 if(
sizeof(
long) >= 8 ) {
424 int64_t topbits1, topbits2;
426 topbits1 = ( (int64_t) seed >> 32) & 0xffff ;
427 topbits2 = ( (int64_t) seed >> 48) & 0xffff ;
429 topbits1 = detail::rshift<32>(
seed) & 0xffff ;
430 topbits2 = detail::rshift<48>(
seed) & 0xffff ;
432 init_table[0] ^= topbits1;
433 init_table[2] ^= topbits2;
438 for(i = 0;i < 12; i++){
462 const int ecuyer_a = 53668;
463 const int ecuyer_b = 40014;
464 const int ecuyer_c = 12211;
465 const int ecuyer_d = 2147483563;
467 const int lux_levels[3] = {109, 202, 397};
484 if( (lux > 2)||(lux < 0) ){
485 pDiscard = (lux >= 12) ? (lux-12) : lux_levels[1];
493 long next_seed = *seeds;
497 for( i = 0;(i != 24)&&(*seedptr != 0);i++){
498 init_table[i] = *seedptr & 0xffffffff;
503 next_seed = init_table[i-1];
505 k_multiple = next_seed / ecuyer_a;
506 next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
507 - k_multiple * ecuyer_c;
509 next_seed += ecuyer_d;
511 next_seed &= 0xffffffff;
512 init_table[i] = next_seed;
516 for(i = 0;i < 12; i++){
529 std::ofstream outFile( filename, std::ios::out ) ;
530 if (!outFile.bad()) {
532 std::vector<unsigned long>
v =
put();
533 for (
unsigned int i=0; i<v.size(); ++i) {
534 outFile << v[i] <<
"\n";
543 std::cerr <<
" -- Engine state remains unchanged\n";
547 std::vector<unsigned long>
v;
552 inFile.clear(std::ios::badbit | inFile.rdstate());
553 std::cerr <<
"\nJamesRandom state (vector) description improper."
554 <<
"\nrestoreStatus has failed."
555 <<
"\nInput stream is probably mispositioned now." << std::endl;
564 if (!inFile.bad() && !inFile.eof()) {
566 for (
int i=0; i<12; ++i) {
578 std::cout << std::endl;
579 std::cout <<
"--------- Ranlux engine status ---------" << std::endl;
580 std::cout <<
" Initial seed = " <<
theSeed << std::endl;
581 std::cout <<
" randoms[] = ";
582 for (
int i=0; i<12; ++i) {
583 std::cout <<
randoms[i] << std::endl;
585 std::cout << std::endl;
586 std::cout <<
" carry = " <<
carry <<
", index = " <<
index << std::endl;
587 std::cout <<
" luxury = " <<
luxury <<
" pDiscard = "
589 std::cout <<
"----------------------------------------" << std::endl;
594 char beginMarker[] =
"Ranlux64Engine-begin";
595 os << beginMarker <<
"\nUvec\n";
596 std::vector<unsigned long>
v =
put();
597 for (
unsigned int i=0; i<v.size(); ++i) {
604 std::vector<unsigned long>
v;
605 v.push_back (engineIDulong<Ranlux64Engine>());
606 std::vector<unsigned long>
t;
607 for (
int i=0; i<12; ++i) {
609 v.push_back(t[0]); v.push_back(t[1]);
612 v.push_back(t[0]); v.push_back(t[1]);
613 v.push_back(static_cast<unsigned long>(
index));
614 v.push_back(static_cast<unsigned long>(
luxury));
615 v.push_back(static_cast<unsigned long>(
pDiscard));
627 if (strcmp(beginMarker,
"Ranlux64Engine-begin")) {
628 is.clear(std::ios::badbit | is.rdstate());
629 std::cerr <<
"\nInput stream mispositioned or"
630 <<
"\nRanlux64Engine state description missing or"
631 <<
"\nwrong engine type found." << std::endl;
638 return "Ranlux64Engine-begin";
644 std::vector<unsigned long>
v;
649 is.clear(std::ios::badbit | is.rdstate());
650 std::cerr <<
"\nRanlux64Engine state (vector) description improper."
651 <<
"\ngetState() has failed."
652 <<
"\nInput stream is probably mispositioned now." << std::endl;
664 for (
int i=0; i<12; ++i) {
674 if (strcmp(endMarker,
"Ranlux64Engine-end")) {
675 is.clear(std::ios::badbit | is.rdstate());
676 std::cerr <<
"\nRanlux64Engine state description incomplete."
677 <<
"\nInput stream is probably mispositioned now." << std::endl;
684 if ((v[0] & 0xffffffffUL) != engineIDulong<Ranlux64Engine>()) {
686 "\nRanlux64Engine get:state vector has wrong ID word - state unchanged\n";
695 "\nRanlux64Engine get:state vector has wrong length - state unchanged\n";
698 std::vector<unsigned long>
t(2);
699 for (
int i=0; i<12; ++i) {
700 t[0] = v[2*i+1]; t[1] = v[2*i+2];
703 t[0] = v[25]; t[1] = v[26];