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

RandomObjects/CLHEP/Random/TripleRand.h
Go to the documentation of this file.
1 // $Id: TripleRand.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // Hep Random
6 // --- TripleRand ---
7 // class header file
8 // -----------------------------------------------------------------------
9 // A canopy pseudo-random number generator. Using the Tausworthe
10 // exclusive-or shift register, a simple Integer Coungruence generator, and
11 // the Hurd 288 total bit shift register, all XOR'd with each other, we
12 // provide an engine that should be a fairly good "mother" generator.
13 //
14 // This is similar to DualRand, with the addition of the Hurd288Engine.
15 // From DualRand, we have the following:
16 // Exclusive or of a feedback shift register and integer congruence
17 // random number generator. The feedback shift register uses offsets
18 // 127 and 97. The integer congruence generator uses a different
19 // multiplier for each stream. The multipliers are chosen to give
20 // full period and maximum "potency" for modulo 2^32. The period of
21 // the combined random number generator is 2^159 - 2^32, and the
22 // sequences are different for each stream (not just started in a
23 // different place).
24 // The above is then amended to also add in the exclusive or of the
25 // 288-total bit Hurd engine which in this case is a series of 32
26 // interconnected 9-bit shift registers, with the newest bit of each register
27 // formed by the XOR of the previous bit and some bit b-d from a previous
28 // register where d is chosen to create a primitive polynomial to maximize
29 // the period.
30 // =======================================================================
31 // Ken Smith - Initial draft started: 23rd Jul 1998
32 // - Added conversion operators: 6th Aug 1998
33 // M Fischler - Big merge with CLHEP 13 May 1999
34 // - Elimination of unused Taus() and Cong() accessors
35 // Mark Fischler Methods put, get for instance save/restore 12/8/04
36 // Mark Fischler methods for anonymous save/restore 12/27/04
37 // =======================================================================
38 
39 #ifndef TripleRand_h
40 #define TripleRand_h
41 
42 #include "CLHEP/Random/defs.h"
43 #include "CLHEP/Random/RandomEngine.h"
44 #include "CLHEP/Random/Hurd288Engine.h"
45 
46 namespace CLHEP {
47 
52 class TripleRand: public HepRandomEngine {
53 
54 public:
55 
56  TripleRand();
57  TripleRand( long seed );
58  TripleRand( std::istream & is );
59  TripleRand( int rowIndex, int colIndex );
60  virtual ~TripleRand();
61  // Constructors and destructor
62 
63  double flat();
64  // Returns a pseudo random number between 0 and 1
65  // (excluding the end points)
66 
67  void flatArray( const int size, double * vect );
68  // Fills an array "vect" of specified size with flat random values.
69 
70  void setSeed( long seed, int );
71  // Sets the state of the algorithm according to seed.
72 
73  void setSeeds( const long * seeds, int );
74  // Sets the state of the algorithm according to the zero-terminated
75  // array of seeds.
76 
77  void saveStatus( const char filename[] = "TripleRand.conf" ) const;
78  // Saves on named file the current engine status.
79 
80  void restoreStatus( const char filename[] = "TripleRand.conf" );
81  // Reads from named file the last saved engine status and restores it.
82 
83  void showStatus() const;
84  // Dumps the current engine status on the screen.
85 
86  operator float(); // flat value, without worrying about filling bits
87  operator unsigned int(); // 32-bit flat value, quickest of all
88 
89  virtual std::ostream & put (std::ostream & os) const;
90  virtual std::istream & get (std::istream & is);
91  static std::string beginTag ( );
92  virtual std::istream & getState ( std::istream & is );
93 
94  std::string name() const;
95  static std::string engineName() {return "TripleRand";}
96 
97  std::vector<unsigned long> put () const;
98  bool get (const std::vector<unsigned long> & v);
99  bool getState (const std::vector<unsigned long> & v);
100 
101  static const unsigned int VECTOR_STATE_SIZE = 20;
102 
103 private:
104 
105  static int numEngines;
106 
111 class Tausworthe {
112 public:
113 
114  Tausworthe();
115  Tausworthe(unsigned int seed);
116 
117  operator unsigned int();
118 
119  void put( std::ostream & os ) const;
120  void put(std::vector<unsigned long> & v) const;
121  void get( std::istream & is );
122  bool get(std::vector<unsigned long>::const_iterator & iv);
123 
124 private:
125 
126  int wordIndex;
127  unsigned int words[4];
128 }; // Tausworthe
129 
134 class IntegerCong {
135 public:
136 
137  IntegerCong();
138  IntegerCong(unsigned int seed, int streamNumber);
139 
140  operator unsigned int();
141 
142  void put( std::ostream & os ) const;
143  void put(std::vector<unsigned long> & v) const;
144  void get( std::istream & is );
145  bool get(std::vector<unsigned long>::const_iterator & iv);
146 
147 private:
148 
149  unsigned int state, multiplier, addend;
150 }; // IntegerCong
151 
152  Hurd288Engine & Hurd(); // retrieve the constituent engine for input
153 
154  const Tausworthe & ConstTaus() const; // Same as above
155  const IntegerCong & ConstCong() const; // necessary for
156  const Hurd288Engine & ConstHurd() const; // output
157 
158  Tausworthe tausworthe; // Instances of each of the
159  IntegerCong integerCong; // three engines that combine to make
160  Hurd288Engine hurd; // one TripleRand instance
161 
162 }; // TripleRand
163 
164 } // namespace CLHEP
165 
166 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
167 // backwards compatibility will be enabled ONLY in CLHEP 1.9
168 using namespace CLHEP;
169 #endif
170 
171 #endif // TripleRand_h
CLHEP::TripleRand::beginTag
static std::string beginTag()
Definition: TripleRand.cc:266
CLHEP::TripleRand::~TripleRand
virtual ~TripleRand()
Definition: TripleRand.cc:92
CLHEP::TripleRand::getState
virtual std::istream & getState(std::istream &is)
Definition: TripleRand.cc:270
CLHEP::TripleRand::get
virtual std::istream & get(std::istream &is)
Definition: TripleRand.cc:249
CLHEP::TripleRand::put
std::vector< unsigned long > put() const
Definition: TripleRand.cc:237
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
CLHEP::TripleRand::restoreStatus
void restoreStatus(const char filename[]="TripleRand.conf")
Definition: TripleRand.cc:149
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::TripleRand::setSeeds
void setSeeds(const long *seeds, int)
Definition: TripleRand.cc:117
CLHEP::TripleRand::flat
double flat()
Definition: TripleRand.cc:94
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::TripleRand::setSeed
void setSeed(long seed, int)
Definition: TripleRand.cc:110
CLHEP::TripleRand::saveStatus
void saveStatus(const char filename[]="TripleRand.conf") const
Definition: TripleRand.cc:122
CLHEP
Definition: ClhepVersion.h:13
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::TripleRand::showStatus
void showStatus() const
Definition: TripleRand.cc:185
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::TripleRand::flatArray
void flatArray(const int size, double *vect)
Definition: TripleRand.cc:104
CLHEP::TripleRand::VECTOR_STATE_SIZE
static const unsigned int VECTOR_STATE_SIZE
Definition: Matrix/CLHEP/Random/TripleRand.h:101
CLHEP::TripleRand::name
std::string name() const
Definition: TripleRand.cc:56
CLHEP::TripleRand::engineName
static std::string engineName()
Definition: RandomObjects/CLHEP/Random/TripleRand.h:95
CLHEP::TripleRand::TripleRand
TripleRand()
Definition: TripleRand.cc:58