Geant4  10.02.p01
Ranlux64Engine.cc
Go to the documentation of this file.
1 // $Id:$
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // HEP Random
6 // --- Ranlux64Engine ---
7 // class implementation file
8 // -----------------------------------------------------------------------
9 // A double-precision implementation of the RanluxEngine generator as
10 // decsribed by the notes of the original ranlux author (Martin Luscher)
11 //
12 // See the note by Martin Luscher, December 1997, entitiled
13 // Double-precision implementation of the random number generator ranlux
14 //
15 // =======================================================================
16 // Ken Smith - Initial draft: 14th Jul 1998
17 // - Removed pow() from flat method 14th Jul 1998
18 // - Added conversion operators: 6th Aug 1998
19 //
20 // Mark Fischler The following were modified mostly to make the routine
21 // exactly match the Luscher algorithm in generating 48-bit
22 // randoms:
23 // 9/9/98 - Substantial changes in what used to be flat() to match
24 // algorithm in Luscher's ranlxd.c
25 // - Added update() method for 12 numbers, making flat() trivial
26 // - Added advance() method to hold the unrolled loop for update
27 // - Distinction between three forms of seeding such that it
28 // is impossible to get same sequence from different forms -
29 // done by discarding some fraction of one macro cycle which
30 // is different for the three cases
31 // - Change the misnomer "seed_table" to the more accurate
32 // "randoms"
33 // - Removed the no longer needed count12, i_lag, j_lag, etc.
34 // - Corrected seed procedure which had been filling bits past
35 // 2^-48. This actually was very bad, invalidating the
36 // number theory behind the proof that ranlxd is good.
37 // - Addition of 2**(-49) to generated number to prevent zero
38 // from being returned; this does not affect the sequence
39 // itself.
40 // - Corrected ecu seeding, which had been supplying only
41 // numbers less than 1/2. This is probably moot.
42 // 9/15/98 - Modified use of the various exponents of 2
43 // to avoid per-instance space overhead. Note that these
44 // are initialized in setSeed, which EVERY constructor
45 // must invoke.
46 // J. Marraffino - Remove dependence on hepString class 13 May 1999
47 // M. Fischler - In restore, checkFile for file not found 03 Dec 2004
48 // M. Fischler - put get Methods for distrib instance save/restore 12/8/04
49 // M. Fischler - split get() into tag validation and
50 // getState() for anonymous restores 12/27/04
51 // M. Fischler - put/get for vectors of ulongs 3/14/05
52 // M. Fischler - State-saving using only ints, for portability 4/12/05
53 //
54 // =======================================================================
55 
56 #include "CLHEP/Random/Random.h"
57 #include "CLHEP/Random/Ranlux64Engine.h"
58 #include "CLHEP/Random/engineIDulong.h"
59 #include "CLHEP/Random/DoubConv.h"
60 #include "CLHEP/Utility/atomic_int.h"
61 
62 #include <string.h> // for strcmp
63 #include <cstdlib> // for std::abs(int)
64 #include <limits> // for numeric_limits
65 
66 namespace CLHEP {
67 
68 namespace {
69  // Number of instances with automatic seed selection
70  CLHEP_ATOMIC_INT_TYPE numberOfEngines(0);
71 
72  // Maximum index into the seed table
73  const int maxIndex = 215;
74 }
75 
76 static const int MarkerLen = 64; // Enough room to hold a begin or end marker.
77 
78 
79 #ifndef WIN32
80 namespace detail {
81 
82 template< std::size_t n,
83  bool = n < std::size_t(std::numeric_limits<unsigned long>::digits) >
84  struct do_right_shift;
85 template< std::size_t n >
86  struct do_right_shift<n,true>
87 {
88  unsigned long operator()(unsigned long value) { return value >> n; }
89 };
90 template< std::size_t n >
91  struct do_right_shift<n,false>
92 {
93  unsigned long operator()(unsigned long) { return 0ul; }
94 };
95 
96 template< std::size_t nbits >
97  unsigned long rshift( unsigned long value )
98 { return do_right_shift<nbits>()(value); }
99 
100 } // namespace detail
101 #endif
102 
103 std::string Ranlux64Engine::name() const {return "Ranlux64Engine";}
104 
105 Ranlux64Engine::Ranlux64Engine()
106 : HepRandomEngine()
107 {
108  luxury = 1;
109  int numEngines = numberOfEngines++;
110  int cycle = std::abs(int(numEngines/maxIndex));
111  int curIndex = std::abs(int(numEngines%maxIndex));
112 
113  long mask = ((cycle & 0x007fffff) << 8);
114  long seedlist[2];
115  HepRandom::getTheTableSeeds( seedlist, curIndex );
116  seedlist[0] ^= mask;
117  seedlist[1] = 0;
118 
119  setSeeds(seedlist, luxury);
120  advance ( 8 ); // Discard some iterations and ensure that
121  // this sequence won't match one where seeds
122  // were provided.
123 }
124 
125 Ranlux64Engine::Ranlux64Engine(long seed, int lux)
126 : HepRandomEngine()
127 {
128  luxury = lux;
129  long seedlist[2]={seed,0};
130  setSeeds(seedlist, lux);
131  advance ( 2*lux + 1 ); // Discard some iterations to use a different
132  // point in the sequence.
133 }
134 
135 Ranlux64Engine::Ranlux64Engine(int rowIndex, int, int lux)
136 : HepRandomEngine()
137 {
138  luxury = lux;
139  int cycle = std::abs(int(rowIndex/maxIndex));
140  int row = std::abs(int(rowIndex%maxIndex));
141  long mask = (( cycle & 0x000007ff ) << 20 );
142  long seedlist[2];
143  HepRandom::getTheTableSeeds( seedlist, row );
144  seedlist[0] ^= mask;
145  seedlist[1]= 0;
146  setSeeds(seedlist, lux);
147 }
148 
149 Ranlux64Engine::Ranlux64Engine( std::istream& is )
150 : HepRandomEngine()
151 {
152  is >> *this;
153 }
154 
155 Ranlux64Engine::~Ranlux64Engine() {}
156 
157 double Ranlux64Engine::flat() {
158  // Luscher improves the speed by computing several numbers in a shot,
159  // in a manner similar to that of the Tausworth in DualRand or the Hurd
160  // engines. Thus, the real work is done in update(). Here we merely ensure
161  // that zero, which the algorithm can produce, is never returned by flat().
162 
163  if (index <= 0) update();
164  return randoms[--index] + twoToMinus_49();
165 }
166 
167 void Ranlux64Engine::update() {
168  // Update the stash of twelve random numbers.
169  // When this routione is entered, index is always 0. The randoms
170  // contains the last 12 numbers in the sequents: s[0] is x[a+11],
171  // s[1] is x[a+10] ... and s[11] is x[a] for some a. Carry contains
172  // the last carry value (c[a+11]).
173  //
174  // The recursion relation (3) in Luscher's note says
175  // delta[n] = x[n-s] = x[n-r] -c[n-1] or for n=a+12,
176  // delta[a+12] = x[a+7] - x[a] -c[a+11] where we use r=12, s=5 per eqn. (7)
177  // This reduces to
178  // s[11] = s[4] - s[11] - carry.
179  // The next number similarly will be given by s[10] = s[3] - s[10] - carry,
180  // and so forth until s[0] is filled.
181  //
182  // However, we need to skip 397, 202 or 109 numbers - these are not divisible
183  // by 12 - to "fare well in the spectral test".
184 
185  advance(pDozens);
186 
187  // Since we wish at the end to have the 12 last numbers in the order of
188  // s[11] first, till s[0] last, we will have to do 1, 10, or 1 iterations
189  // and then re-arrange to place to get the oldest one in s[11].
190  // Generically, this will imply re-arranging the s array at the end,
191  // but we can treat the special case of endIters = 1 separately for superior
192  // efficiency in the cases of levels 0 and 2.
193 
194  double y1;
195 
196  if ( endIters == 1 ) { // Luxury levels 0 and 2 will go here
197  y1 = randoms[ 4] - randoms[11] - carry;
198  if ( y1 < 0.0 ) {
199  y1 += 1.0;
200  carry = twoToMinus_48();
201  } else {
202  carry = 0.0;
203  }
204  randoms[11] = randoms[10];
205  randoms[10] = randoms[ 9];
206  randoms[ 9] = randoms[ 8];
207  randoms[ 8] = randoms[ 7];
208  randoms[ 7] = randoms[ 6];
209  randoms[ 6] = randoms[ 5];
210  randoms[ 5] = randoms[ 4];
211  randoms[ 4] = randoms[ 3];
212  randoms[ 3] = randoms[ 2];
213  randoms[ 2] = randoms[ 1];
214  randoms[ 1] = randoms[ 0];
215  randoms[ 0] = y1;
216 
217  } else {
218 
219  int m, nr, ns;
220  for ( m = 0, nr = 11, ns = 4; m < endIters; ++m, --nr ) {
221  y1 = randoms [ns] - randoms[nr] - carry;
222  if ( y1 < 0.0 ) {
223  y1 += 1.0;
224  carry = twoToMinus_48();
225  } else {
226  carry = 0.0;
227  }
228  randoms[nr] = y1;
229  --ns;
230  if ( ns < 0 ) {
231  ns = 11;
232  }
233  } // loop on m
234 
235  double temp[12];
236  for (m=0; m<12; m++) {
237  temp[m]=randoms[m];
238  }
239 
240  ns = 11 - endIters;
241  for (m=11; m>=0; --m) {
242  randoms[m] = temp[ns];
243  --ns;
244  if ( ns < 0 ) {
245  ns = 11;
246  }
247  }
248 
249  }
250 
251  // Now when we return, there are 12 fresh usable numbers in s[11] ... s[0]
252 
253  index = 11;
254 
255 } // update()
256 
257 void Ranlux64Engine::advance(int dozens) {
258 
259  double y1, y2, y3;
260  double cValue = twoToMinus_48();
261  double zero = 0.0;
262  double one = 1.0;
263 
264  // Technical note: We use Luscher's trick to only do the
265  // carry subtraction when we really have to. Like him, we use
266  // three registers instead of two so that we avoid sequences
267  // like storing y1 then immediately replacing its value:
268  // some architectures lose time when this is done.
269 
270  // Luscher's ranlxd.c fills the stash going
271  // upward. We fill it downward to save a bit of time in the
272  // flat() routine at no cost later. This means that while
273  // Luscher's ir is jr+5, our n-r is (n-s)-5. (Note that
274  // though ranlxd.c initializes ir and jr to 11 and 7, ir as
275  // used is 5 more than jr because update is entered after
276  // incrementing ir.)
277  //
278 
279  // I have CAREFULLY checked that the algorithms do match
280  // in all details.
281 
282  int k;
283  for ( k = dozens; k > 0; --k ) {
284 
285  y1 = randoms[ 4] - randoms[11] - carry;
286 
287  y2 = randoms[ 3] - randoms[10];
288  if ( y1 < zero ) {
289  y1 += one;
290  y2 -= cValue;
291  }
292  randoms[11] = y1;
293 
294  y3 = randoms[ 2] - randoms[ 9];
295  if ( y2 < zero ) {
296  y2 += one;
297  y3 -= cValue;
298  }
299  randoms[10] = y2;
300 
301  y1 = randoms[ 1] - randoms[ 8];
302  if ( y3 < zero ) {
303  y3 += one;
304  y1 -= cValue;
305  }
306  randoms[ 9] = y3;
307 
308  y2 = randoms[ 0] - randoms[ 7];
309  if ( y1 < zero ) {
310  y1 += one;
311  y2 -= cValue;
312  }
313  randoms[ 8] = y1;
314 
315  y3 = randoms[11] - randoms[ 6];
316  if ( y2 < zero ) {
317  y2 += one;
318  y3 -= cValue;
319  }
320  randoms[ 7] = y2;
321 
322  y1 = randoms[10] - randoms[ 5];
323  if ( y3 < zero ) {
324  y3 += one;
325  y1 -= cValue;
326  }
327  randoms[ 6] = y3;
328 
329  y2 = randoms[ 9] - randoms[ 4];
330  if ( y1 < zero ) {
331  y1 += one;
332  y2 -= cValue;
333  }
334  randoms[ 5] = y1;
335 
336  y3 = randoms[ 8] - randoms[ 3];
337  if ( y2 < zero ) {
338  y2 += one;
339  y3 -= cValue;
340  }
341  randoms[ 4] = y2;
342 
343  y1 = randoms[ 7] - randoms[ 2];
344  if ( y3 < zero ) {
345  y3 += one;
346  y1 -= cValue;
347  }
348  randoms[ 3] = y3;
349 
350  y2 = randoms[ 6] - randoms[ 1];
351  if ( y1 < zero ) {
352  y1 += one;
353  y2 -= cValue;
354  }
355  randoms[ 2] = y1;
356 
357  y3 = randoms[ 5] - randoms[ 0];
358  if ( y2 < zero ) {
359  y2 += one;
360  y3 -= cValue;
361  }
362  randoms[ 1] = y2;
363 
364  if ( y3 < zero ) {
365  y3 += one;
366  carry = cValue;
367  }
368  randoms[ 0] = y3;
369 
370  } // End of major k loop doing 12 numbers at each cycle
371 
372 } // advance(dozens)
373 
374 void Ranlux64Engine::flatArray(const int size, double* vect) {
375  for( int i=0; i < size; ++i ) {
376  vect[i] = flat();
377  }
378 }
379 
380 void Ranlux64Engine::setSeed(long seed, int lux) {
381 
382 // The initialization is carried out using a Multiplicative
383 // Congruential generator using formula constants of L'Ecuyer
384 // as described in "A review of pseudorandom number generators"
385 // (Fred James) published in Computer Physics Communications 60 (1990)
386 // pages 329-344
387 
388  const int ecuyer_a(53668);
389  const int ecuyer_b(40014);
390  const int ecuyer_c(12211);
391  const int ecuyer_d(2147483563);
392 
393  const int lux_levels[3] = {109, 202, 397};
394  theSeed = seed;
395 
396  if( (lux > 2)||(lux < 0) ){
397  pDiscard = (lux >= 12) ? (lux-12) : lux_levels[1];
398  }else{
399  pDiscard = lux_levels[luxury];
400  }
401  pDozens = pDiscard / 12;
402  endIters = pDiscard % 12;
403 
404  long init_table[24];
405  long next_seed = seed;
406  long k_multiple;
407  int i;
408  next_seed &= 0xffffffff;
409  while( next_seed >= ecuyer_d ) {
410  next_seed -= ecuyer_d;
411  }
412 
413  for(i = 0;i != 24;i++){
414  k_multiple = next_seed / ecuyer_a;
415  next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
416  - k_multiple * ecuyer_c;
417  if(next_seed < 0) {
418  next_seed += ecuyer_d;
419  }
420  next_seed &= 0xffffffff;
421  init_table[i] = next_seed;
422  }
423  // are we on a 64bit machine?
424  if( sizeof(long) >= 8 ) {
425  long topbits1, topbits2;
426 #ifdef WIN32
427  topbits1 = ( seed >> 32) & 0xffff ;
428  topbits2 = ( seed >> 48) & 0xffff ;
429 #else
430  topbits1 = detail::rshift<32>(seed) & 0xffff ;
431  topbits2 = detail::rshift<48>(seed) & 0xffff ;
432 #endif
433  init_table[0] ^= topbits1;
434  init_table[2] ^= topbits2;
435  //std::cout << " init_table[0] " << init_table[0] << " from " << topbits1 << std::endl;
436  //std::cout << " init_table[2] " << init_table[2] << " from " << topbits2 << std::endl;
437  }
438 
439  for(i = 0;i < 12; i++){
440  randoms[i] = (init_table[2*i ] ) * 2.0 * twoToMinus_32() +
441  (init_table[2*i+1] >> 15) * twoToMinus_48();
442  //if( randoms[i] < 0. || randoms[i] > 1. ) {
443  //std::cout << "setSeed: init_table " << init_table[2*i ] << std::endl;
444  //std::cout << "setSeed: init_table " << init_table[2*i+1] << std::endl;
445  //std::cout << "setSeed: random " << i << " is " << randoms[i] << std::endl;
446  //}
447  }
448 
449  carry = 0.0;
450  if ( randoms[11] == 0. ) carry = twoToMinus_48();
451  index = 11;
452 
453 } // setSeed()
454 
455 void Ranlux64Engine::setSeeds(const long * seeds, int lux) {
456 // old code only uses the first long in seeds
457 // setSeed( *seeds ? *seeds : 32767, lux );
458 // theSeeds = seeds;
459 
460 // using code from Ranlux - even those are 32bit seeds,
461 // that is good enough to completely differentiate the sequences
462 
463  const int ecuyer_a = 53668;
464  const int ecuyer_b = 40014;
465  const int ecuyer_c = 12211;
466  const int ecuyer_d = 2147483563;
467 
468  const int lux_levels[3] = {109, 202, 397};
469  const long *seedptr;
470 
471  theSeeds = seeds;
472  seedptr = seeds;
473 
474  if(seeds == 0){
475  setSeed(theSeed,lux);
476  theSeeds = &theSeed;
477  return;
478  }
479 
480  theSeed = *seeds;
481 
482 // number of additional random numbers that need to be 'thrown away'
483 // every 24 numbers is set using luxury level variable.
484 
485  if( (lux > 2)||(lux < 0) ){
486  pDiscard = (lux >= 12) ? (lux-12) : lux_levels[1];
487  }else{
488  pDiscard = lux_levels[luxury];
489  }
490  pDozens = pDiscard / 12;
491  endIters = pDiscard % 12;
492 
493  long init_table[24];
494  long next_seed = *seeds;
495  long k_multiple;
496  int i;
497 
498  for( i = 0;(i != 24)&&(*seedptr != 0);i++){
499  init_table[i] = *seedptr & 0xffffffff;
500  seedptr++;
501  }
502 
503  if(i != 24){
504  next_seed = init_table[i-1];
505  for(;i != 24;i++){
506  k_multiple = next_seed / ecuyer_a;
507  next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
508  - k_multiple * ecuyer_c;
509  if(next_seed < 0) {
510  next_seed += ecuyer_d;
511  }
512  next_seed &= 0xffffffff;
513  init_table[i] = next_seed;
514  }
515  }
516 
517  for(i = 0;i < 12; i++){
518  randoms[i] = (init_table[2*i ] ) * 2.0 * twoToMinus_32() +
519  (init_table[2*i+1] >> 15) * twoToMinus_48();
520  }
521 
522  carry = 0.0;
523  if ( randoms[11] == 0. ) carry = twoToMinus_48();
524  index = 11;
525 
526 }
527 
528 void Ranlux64Engine::saveStatus( const char filename[] ) const
529 {
530  std::ofstream outFile( filename, std::ios::out ) ;
531  if (!outFile.bad()) {
532  outFile << "Uvec\n";
533  std::vector<unsigned long> v = put();
534  for (unsigned int i=0; i<v.size(); ++i) {
535  outFile << v[i] << "\n";
536  }
537  }
538 }
539 
540 void Ranlux64Engine::restoreStatus( const char filename[] )
541 {
542  std::ifstream inFile( filename, std::ios::in);
543  if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
544  std::cerr << " -- Engine state remains unchanged\n";
545  return;
546  }
547  if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
548  std::vector<unsigned long> v;
549  unsigned long xin;
550  for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
551  inFile >> xin;
552  if (!inFile) {
553  inFile.clear(std::ios::badbit | inFile.rdstate());
554  std::cerr << "\nJamesRandom state (vector) description improper."
555  << "\nrestoreStatus has failed."
556  << "\nInput stream is probably mispositioned now." << std::endl;
557  return;
558  }
559  v.push_back(xin);
560  }
561  getState(v);
562  return;
563  }
564 
565  if (!inFile.bad() && !inFile.eof()) {
566 // inFile >> theSeed; removed -- encompased by possibleKeywordInput
567  for (int i=0; i<12; ++i) {
568  inFile >> randoms[i];
569  }
570  inFile >> carry; inFile >> index;
571  inFile >> luxury; inFile >> pDiscard;
572  pDozens = pDiscard / 12;
573  endIters = pDiscard % 12;
574  }
575 }
576 
577 void Ranlux64Engine::showStatus() const
578 {
579  std::cout << std::endl;
580  std::cout << "--------- Ranlux engine status ---------" << std::endl;
581  std::cout << " Initial seed = " << theSeed << std::endl;
582  std::cout << " randoms[] = ";
583  for (int i=0; i<12; ++i) {
584  std::cout << randoms[i] << std::endl;
585  }
586  std::cout << std::endl;
587  std::cout << " carry = " << carry << ", index = " << index << std::endl;
588  std::cout << " luxury = " << luxury << " pDiscard = "
589  << pDiscard << std::endl;
590  std::cout << "----------------------------------------" << std::endl;
591 }
592 
593 std::ostream & Ranlux64Engine::put( std::ostream& os ) const
594 {
595  char beginMarker[] = "Ranlux64Engine-begin";
596  os << beginMarker << "\nUvec\n";
597  std::vector<unsigned long> v = put();
598  for (unsigned int i=0; i<v.size(); ++i) {
599  os << v[i] << "\n";
600  }
601  return os;
602 }
603 
604 std::vector<unsigned long> Ranlux64Engine::put () const {
605  std::vector<unsigned long> v;
606  v.push_back (engineIDulong<Ranlux64Engine>());
607  std::vector<unsigned long> t;
608  for (int i=0; i<12; ++i) {
609  t = DoubConv::dto2longs(randoms[i]);
610  v.push_back(t[0]); v.push_back(t[1]);
611  }
612  t = DoubConv::dto2longs(carry);
613  v.push_back(t[0]); v.push_back(t[1]);
614  v.push_back(static_cast<unsigned long>(index));
615  v.push_back(static_cast<unsigned long>(luxury));
616  v.push_back(static_cast<unsigned long>(pDiscard));
617  return v;
618 }
619 
620 std::istream & Ranlux64Engine::get ( std::istream& is )
621 {
622  char beginMarker [MarkerLen];
623  is >> std::ws;
624  is.width(MarkerLen); // causes the next read to the char* to be <=
625  // that many bytes, INCLUDING A TERMINATION \0
626  // (Stroustrup, section 21.3.2)
627  is >> beginMarker;
628  if (strcmp(beginMarker,"Ranlux64Engine-begin")) {
629  is.clear(std::ios::badbit | is.rdstate());
630  std::cerr << "\nInput stream mispositioned or"
631  << "\nRanlux64Engine state description missing or"
632  << "\nwrong engine type found." << std::endl;
633  return is;
634  }
635  return getState(is);
636 }
637 
638 std::string Ranlux64Engine::beginTag ( ) {
639  return "Ranlux64Engine-begin";
640 }
641 
642 std::istream & Ranlux64Engine::getState ( std::istream& is )
643 {
644  if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
645  std::vector<unsigned long> v;
646  unsigned long uu;
647  for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
648  is >> uu;
649  if (!is) {
650  is.clear(std::ios::badbit | is.rdstate());
651  std::cerr << "\nRanlux64Engine state (vector) description improper."
652  << "\ngetState() has failed."
653  << "\nInput stream is probably mispositioned now." << std::endl;
654  return is;
655  }
656  v.push_back(uu);
657  }
658  getState(v);
659  return (is);
660  }
661 
662 // is >> theSeed; Removed, encompassed by possibleKeywordInput()
663 
664  char endMarker [MarkerLen];
665  for (int i=0; i<12; ++i) {
666  is >> randoms[i];
667  }
668  is >> carry; is >> index;
669  is >> luxury; is >> pDiscard;
670  pDozens = pDiscard / 12;
671  endIters = pDiscard % 12;
672  is >> std::ws;
673  is.width(MarkerLen);
674  is >> endMarker;
675  if (strcmp(endMarker,"Ranlux64Engine-end")) {
676  is.clear(std::ios::badbit | is.rdstate());
677  std::cerr << "\nRanlux64Engine state description incomplete."
678  << "\nInput stream is probably mispositioned now." << std::endl;
679  return is;
680  }
681  return is;
682 }
683 
684 bool Ranlux64Engine::get (const std::vector<unsigned long> & v) {
685  if ((v[0] & 0xffffffffUL) != engineIDulong<Ranlux64Engine>()) {
686  std::cerr <<
687  "\nRanlux64Engine get:state vector has wrong ID word - state unchanged\n";
688  return false;
689  }
690  return getState(v);
691 }
692 
693 bool Ranlux64Engine::getState (const std::vector<unsigned long> & v) {
694  if (v.size() != VECTOR_STATE_SIZE ) {
695  std::cerr <<
696  "\nRanlux64Engine get:state vector has wrong length - state unchanged\n";
697  return false;
698  }
699  std::vector<unsigned long> t(2);
700  for (int i=0; i<12; ++i) {
701  t[0] = v[2*i+1]; t[1] = v[2*i+2];
702  randoms[i] = DoubConv::longs2double(t);
703  }
704  t[0] = v[25]; t[1] = v[26];
705  carry = DoubConv::longs2double(t);
706  index = v[27];
707  luxury = v[28];
708  pDiscard = v[29];
709  return true;
710 }
711 
712 } // namespace CLHEP
unsigned long rshift(unsigned long value)
static const double lux
Definition: G4SIunits.hh:324
static const int MarkerLen
Definition: DualRand.cc:67
static ush mask[]
Definition: csz_inflate.cc:317
G4String name
Definition: TRTMaterials.hh:40
double flat()
Definition: G4AblaRandom.cc:47
unsigned long operator()(unsigned long)
static const double m
Definition: G4SIunits.hh:128
#define ns
Definition: xmlparse.cc:614
void setSeeds(const SeedVector &sv)
Set the seeds of the current generator.
Definition: G4INCLRandom.cc:85