CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Matrix/CLHEP/Random/DualRand.h
Go to the documentation of this file.
1 // $Id: DualRand.h,v 1.5 2010/06/16 17:24:53 garren Exp $
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 
42 #include "CLHEP/Random/defs.h"
43 #include "CLHEP/Random/RandomEngine.h"
44 
45 namespace CLHEP {
46 
51 class DualRand: public HepRandomEngine {
52 
53 public:
54 
55  DualRand();
56  DualRand(long seed);
57  DualRand(std::istream & is);
58  DualRand(int rowIndex, int colIndex);
59  virtual ~DualRand();
60 
61  // let the compiler generate the copy constructors
62  //DualRand(const DualRand & p);
63  //DualRand & operator=(const DualRand & p);
64 
65  double flat();
66  // Returns a pseudo random number between 0 and 1
67  // (excluding the end points)
68 
69  void flatArray(const int size, double * vect);
70  // Fills an array "vect" of specified size with flat random values.
71 
72  void setSeed(long seed, int);
73  // Sets the state of the algorithm according to seed.
74 
75  void setSeeds(const long * seeds, int);
76  // Sets the state of the algorithm according to the zero-terminated
77  // array of seeds.
78 
79  void saveStatus( const char filename[] = "DualRand.conf") const;
80  // Saves on named file the current engine status.
81 
82  void restoreStatus( const char filename[] = "DualRand.conf" );
83  // Reads from named file the last saved engine status and restores it.
84 
85  void showStatus() const;
86  // Dumps the current engine status on the screen.
87 
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  static int numEngines;
108 
109  // This generator is composed of two others combined:
110 
111  class Tausworthe {
112  public:
113  Tausworthe();
114  Tausworthe(unsigned int seed);
115  operator unsigned int();
116  void put(std::ostream & os) const;
117  void put(std::vector<unsigned long> & v) const;
118  void get(std::istream & is);
119  bool get(std::vector<unsigned long>::const_iterator & iv);
120  private:
121  int wordIndex;
122  unsigned int words[4];
123  }; // Tausworthe
124 
125  class IntegerCong {
126  public:
127  IntegerCong();
128  IntegerCong(unsigned int seed, int streamNumber);
129  operator unsigned int();
130  void put(std::ostream & os) const;
131  void put(std::vector<unsigned long> & v) const;
132  void get(std::istream & is);
133  bool get(std::vector<unsigned long>::const_iterator & iv);
134  private:
135  unsigned int state, multiplier, addend;
136  }; // IntegerCong
137 
138  Tausworthe tausworthe;
139  IntegerCong integerCong;
140 
141 }; // DualRand
142 
143 } // namespace CLHEP
144 
145 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
146 // backwards compatibility will be enabled ONLY in CLHEP 1.9
147 using namespace CLHEP;
148 #endif
149 
150 #endif // DualRand_h
CLHEP::HepRandomEngine
Definition: Matrix/CLHEP/Random/RandomEngine.h:55
CLHEP::DualRand::engineName
static std::string engineName()
Definition: Matrix/CLHEP/Random/DualRand.h:97
CLHEP::DualRand::put
std::vector< unsigned long > put() const
Definition: DualRand.cc:243
CLHEP::DualRand::flatArray
void flatArray(const int size, double *vect)
Definition: DualRand.cc:116
CLHEP::DualRand::restoreStatus
void restoreStatus(const char filename[]="DualRand.conf")
Definition: DualRand.cc:162
CLHEP::DualRand::saveStatus
void saveStatus(const char filename[]="DualRand.conf") const
Definition: DualRand.cc:133
CLHEP::DualRand::~DualRand
virtual ~DualRand()
Definition: DualRand.cc:105
CLHEP::DualRand::get
virtual std::istream & get(std::istream &is)
Definition: DualRand.cc:251
CLHEP::DualRand::name
std::string name() const
Definition: DualRand.cc:63
is
HepRotation and so forth isNear() norm2() rectify() static Rotation row1 row4(To avoid bloat in the code pulled in for programs which don 't use all these features, we split the implementation .cc files. Only isNear() goes into the original Rotation.cc) --------------------------------------- HepAxisAngle and HepEulerAngles classes --------------------------------------- These classes are very useful and simple structures for holding the result of a nice intuituve decomposition of a rotation there is no longer much content in the distinct ZOOM PhysicsVectors library The only content left in the library is the object files representing the various Exception objects When we build the CLHEP classes for the ZOOM we will set up so as to use ZOOM SpaceVector is(but we can disable namespace usage and most of our users do so at this point). What I do is leave Hep3Vector in the global namespace
state
ought always be logged and essentially never be ignored ZMexPROBLEM The software has reached a logically impossible internal state
Definition: mechanics_ZMx.txt:159
CLHEP::DualRand::flat
double flat()
Definition: DualRand.cc:107
size
user code seldom needs to call this function directly ZMerrno whether or not they are still recorded ZMerrno size() Return the(integer) number of ZMthrow 'n exceptions currently recorded. 5) ZMerrno.clear() Set an internal counter to zero. This counter is available(see next function) to user code to track ZMthrow 'n exceptions that have occurred during any arbitrary time interval. 6) ZMerrno.countSinceCleared() Return the(integer) number of ZMthrow 'n exceptions that have been recorded via ZMerrno.write()
CLHEP::DualRand::beginTag
static std::string beginTag()
Definition: DualRand.cc:268
CLHEP
Definition: ClhepVersion.h:13
CLHEP::DualRand::setSeeds
void setSeeds(const long *seeds, int)
Definition: DualRand.cc:128
v
they are gone ZOOM Features Discontinued The following features of the ZOOM package were felt to be extreme overkill These have been after checking that no existing user code was utilizing as in SpaceVector v
Definition: keyMergeIssues.doc:324
CLHEP::DualRand::DualRand
DualRand()
Definition: DualRand.cc:74
CLHEP::DualRand::showStatus
void showStatus() const
Definition: DualRand.cc:197
CLHEP::DualRand::getState
virtual std::istream & getState(std::istream &is)
Definition: DualRand.cc:272
seeds
Technical Maintenance Note for CLHEP Random Consequences of seeding JamesRandom with positive seed values greater than In the source code JamesRandom The usual way of seeding a generator is via the default which makes use of the table of seeds(with some trickery to ensure that the values won 't repeat after the table rows are exhausted). The trickery preserves the fact that sees are never negative(because the table values are never negative
CLHEP::DualRand
Definition: Matrix/CLHEP/Random/DualRand.h:51
CLHEP::DualRand::setSeed
void setSeed(long seed, int)
Definition: DualRand.cc:122
CLHEP::DualRand::VECTOR_STATE_SIZE
static const unsigned int VECTOR_STATE_SIZE
Definition: Matrix/CLHEP/Random/DualRand.h:103