Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
DualRand.h
이 파일의 문서화 페이지로 가기
1 // $Id:$
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // Hep Random
6 // --- DualRand ---
7 // class header file
8 // -----------------------------------------------------------------------
9 //
10 // Canopy random number generator DualRand
11 // Re-written as C++ routine for 32-bit ints MF 1/26/98
12 //
13 // Exclusive or of a feedback shift register and integer congruence
14 // random number generator. The feedback shift register uses offsets
15 // 127 and 97. The integer congruence generator uses a different
16 // multiplier for each stream. The multipliers are chosen to give
17 // full period and maximum "potency" for modulo 2^32. The period of
18 // the combined random number generator is 2^159 - 2^32, and the
19 // sequences are different for each stream (not just started in a
20 // different place).
21 //
22 // =======================================================================
23 // Canopy random number generator DualRand.
24 // Doug Toussaint 5/25/88
25 // Optimized by GMH 7/26/88
26 // Optimized by GMH 7/26/88
27 // Repaired by GMH 12/1/88 to update modular congruence state
28 // Put into ranlib by GMH 6/23/89
29 // Re-written as C++ routine for 32-bit ints MF 1/26/98
30 // Re-written for CLHEP package KLS 6/04/98
31 // Removed pow() from flat method for speed KLS 7/21/98
32 // Ken Smith - Added conversion operators: 6th Aug 1998
33 // Mark Fischler methods for distrib. instance save/restore 12/8/04
34 // Mark Fischler methods for anonymous save/restore 12/27/04
35 // Mark Fischler - methods for vector save/restore 3/7/05
36 // =======================================================================
37 
38 
39 #ifndef DualRand_h
40 #define DualRand_h
41 
43 
44 namespace CLHEP {
45 
50 class DualRand: public HepRandomEngine {
51 
52 public:
53 
54  DualRand();
55  DualRand(long seed);
56  DualRand(std::istream & is);
57  DualRand(int rowIndex, int colIndex);
58  virtual ~DualRand();
59 
60  // let the compiler generate the copy constructors
61  //DualRand(const DualRand & p);
62  //DualRand & operator=(const DualRand & p);
63 
64  double flat();
65  // Returns a pseudo random number between 0 and 1
66  // (excluding the end points)
67 
68  void flatArray(const int size, double * vect);
69  // Fills an array "vect" of specified size with flat random values.
70 
71  void setSeed(long seed, int);
72  // Sets the state of the algorithm according to seed.
73 
74  void setSeeds(const long * seeds, int);
75  // Sets the state of the algorithm according to the zero-terminated
76  // array of seeds.
77 
78  void saveStatus( const char filename[] = "DualRand.conf") const;
79  // Saves on named file the current engine status.
80 
81  void restoreStatus( const char filename[] = "DualRand.conf" );
82  // Reads from named file the last saved engine status and restores it.
83 
84  void showStatus() const;
85  // Dumps the current engine status on the screen.
86 
87  operator double(); // Returns same as flat()
88  operator float(); // flat value, without worrying about filling bits
89  operator unsigned int(); // 32-bit flat value, quickest of all
90 
91  virtual std::ostream & put (std::ostream & os) const;
92  virtual std::istream & get (std::istream & is);
93  static std::string beginTag ( );
94  virtual std::istream & getState ( std::istream & is );
95 
96  std::string name() const;
97  static std::string engineName() {return "DualRand";}
98 
99  std::vector<unsigned long> put () const;
100  bool get (const std::vector<unsigned long> & v);
101  bool getState (const std::vector<unsigned long> & v);
102 
103  static const unsigned int VECTOR_STATE_SIZE = 9;
104 
105 private:
106 
107  // This generator is composed of two others combined:
108 
109  class Tausworthe {
110  public:
111  Tausworthe();
112  Tausworthe(unsigned int seed);
113  operator unsigned int();
114  void put(std::ostream & os) const;
115  void put(std::vector<unsigned long> & v) const;
116  void get(std::istream & is);
117  bool get(std::vector<unsigned long>::const_iterator & iv);
118  private:
120  unsigned int words[4];
121  }; // Tausworthe
122 
123  class IntegerCong {
124  public:
125  IntegerCong();
126  IntegerCong(unsigned int seed, int streamNumber);
127  operator unsigned int();
128  void put(std::ostream & os) const;
129  void put(std::vector<unsigned long> & v) const;
130  void get(std::istream & is);
131  bool get(std::vector<unsigned long>::const_iterator & iv);
132  private:
133  unsigned int state, multiplier, addend;
134  }; // IntegerCong
135 
139 
140 }; // DualRand
141 
142 } // namespace CLHEP
143 
144 #endif // DualRand_h
virtual ~DualRand()
Definition: DualRand.cc:111
void flatArray(const int size, double *vect)
Definition: DualRand.cc:122
static std::string engineName()
Definition: DualRand.h:97
void restoreStatus(const char filename[]="DualRand.conf")
Definition: DualRand.cc:150
void put(std::ostream &os) const
Definition: DualRand.cc:474
void saveStatus(const char filename[]="DualRand.conf") const
Definition: DualRand.cc:139
double flat()
Definition: DualRand.cc:113
unsigned int words[4]
Definition: DualRand.h:120
static std::string beginTag()
Definition: DualRand.cc:245
virtual std::istream & getState(std::istream &is)
Definition: DualRand.cc:249
long seed
Definition: chem4.cc:68
std::vector< unsigned long > put() const
Definition: DualRand.cc:220
static const unsigned int VECTOR_STATE_SIZE
Definition: DualRand.h:103
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
void put(std::ostream &os) const
Definition: DualRand.cc:383
void setSeeds(const long *seeds, int)
Definition: DualRand.cc:134
Tausworthe tausworthe
Definition: DualRand.h:137
void showStatus() const
Definition: DualRand.cc:181
IntegerCong integerCong
Definition: DualRand.h:138
std::string name() const
Definition: DualRand.cc:69
void setSeed(long seed, int)
Definition: DualRand.cc:128