|
||||
File indexing completed on 2025-01-30 10:03:30
0001 // $Id: TripleRand.h,v 1.5 2010/06/16 17:24:53 garren Exp $ 0002 // -*- C++ -*- 0003 // 0004 // ----------------------------------------------------------------------- 0005 // Hep Random 0006 // --- TripleRand --- 0007 // class header file 0008 // ----------------------------------------------------------------------- 0009 // A canopy pseudo-random number generator. Using the Tausworthe 0010 // exclusive-or shift register, a simple Integer Coungruence generator, and 0011 // the Hurd 288 total bit shift register, all XOR'd with each other, we 0012 // provide an engine that should be a fairly good "mother" generator. 0013 // 0014 // This is similar to DualRand, with the addition of the Hurd288Engine. 0015 // From DualRand, we have the following: 0016 // Exclusive or of a feedback shift register and integer congruence 0017 // random number generator. The feedback shift register uses offsets 0018 // 127 and 97. The integer congruence generator uses a different 0019 // multiplier for each stream. The multipliers are chosen to give 0020 // full period and maximum "potency" for modulo 2^32. The period of 0021 // the combined random number generator is 2^159 - 2^32, and the 0022 // sequences are different for each stream (not just started in a 0023 // different place). 0024 // The above is then amended to also add in the exclusive or of the 0025 // 288-total bit Hurd engine which in this case is a series of 32 0026 // interconnected 9-bit shift registers, with the newest bit of each register 0027 // formed by the XOR of the previous bit and some bit b-d from a previous 0028 // register where d is chosen to create a primitive polynomial to maximize 0029 // the period. 0030 // ======================================================================= 0031 // Ken Smith - Initial draft started: 23rd Jul 1998 0032 // - Added conversion operators: 6th Aug 1998 0033 // M Fischler - Big merge with CLHEP 13 May 1999 0034 // - Elimination of unused Taus() and Cong() accessors 0035 // Mark Fischler Methods put, get for instance save/restore 12/8/04 0036 // Mark Fischler methods for anonymous save/restore 12/27/04 0037 // ======================================================================= 0038 0039 #ifndef TripleRand_h 0040 #define TripleRand_h 0041 0042 #include "CLHEP/Random/defs.h" 0043 #include "CLHEP/Random/RandomEngine.h" 0044 #include "CLHEP/Random/Hurd288Engine.h" 0045 0046 namespace CLHEP { 0047 0048 /** 0049 * @author 0050 * @ingroup random 0051 */ 0052 class TripleRand: public HepRandomEngine { 0053 0054 public: 0055 0056 TripleRand(); 0057 TripleRand( long seed ); 0058 TripleRand( std::istream & is ); 0059 TripleRand( int rowIndex, int colIndex ); 0060 virtual ~TripleRand(); 0061 // Constructors and destructor 0062 0063 double flat(); 0064 // Returns a pseudo random number between 0 and 1 0065 // (excluding the end points) 0066 0067 void flatArray( const int size, double * vect ); 0068 // Fills an array "vect" of specified size with flat random values. 0069 0070 void setSeed( long seed, int ); 0071 // Sets the state of the algorithm according to seed. 0072 0073 void setSeeds( const long * seeds, int ); 0074 // Sets the state of the algorithm according to the zero-terminated 0075 // array of seeds. 0076 0077 void saveStatus( const char filename[] = "TripleRand.conf" ) const; 0078 // Saves on named file the current engine status. 0079 0080 void restoreStatus( const char filename[] = "TripleRand.conf" ); 0081 // Reads from named file the last saved engine status and restores it. 0082 0083 void showStatus() const; 0084 // Dumps the current engine status on the screen. 0085 0086 operator double(); // Returns same as flat() 0087 operator float(); // flat value, without worrying about filling bits 0088 operator unsigned int(); // 32-bit flat value, quickest of all 0089 0090 virtual std::ostream & put (std::ostream & os) const; 0091 virtual std::istream & get (std::istream & is); 0092 static std::string beginTag ( ); 0093 virtual std::istream & getState ( std::istream & is ); 0094 0095 std::string name() const; 0096 static std::string engineName() {return "TripleRand";} 0097 0098 std::vector<unsigned long> put () const; 0099 bool get (const std::vector<unsigned long> & v); 0100 bool getState (const std::vector<unsigned long> & v); 0101 0102 static const unsigned int VECTOR_STATE_SIZE = 20; 0103 0104 private: 0105 0106 /** 0107 * @author 0108 * @ingroup random 0109 */ 0110 class Tausworthe { 0111 public: 0112 0113 Tausworthe(); 0114 Tausworthe(unsigned int seed); 0115 0116 operator unsigned int(); 0117 0118 void put( std::ostream & os ) const; 0119 void put(std::vector<unsigned long> & v) const; 0120 void get( std::istream & is ); 0121 bool get(std::vector<unsigned long>::const_iterator & iv); 0122 0123 private: 0124 0125 int wordIndex; 0126 unsigned int words[4]; 0127 }; // Tausworthe 0128 0129 /** 0130 * @author 0131 * @ingroup random 0132 */ 0133 class IntegerCong { 0134 public: 0135 0136 IntegerCong(); 0137 IntegerCong(unsigned int seed, int streamNumber); 0138 0139 operator unsigned int(); 0140 0141 void put( std::ostream & os ) const; 0142 void put(std::vector<unsigned long> & v) const; 0143 void get( std::istream & is ); 0144 bool get(std::vector<unsigned long>::const_iterator & iv); 0145 0146 private: 0147 0148 unsigned int state, multiplier, addend; 0149 }; // IntegerCong 0150 0151 Hurd288Engine & Hurd(); // retrieve the constituent engine for input 0152 0153 const Tausworthe & ConstTaus() const; // Same as above 0154 const IntegerCong & ConstCong() const; // necessary for 0155 const Hurd288Engine & ConstHurd() const; // output 0156 0157 int numEngines; 0158 Tausworthe tausworthe; // Instances of each of the 0159 IntegerCong integerCong; // three engines that combine to make 0160 Hurd288Engine hurd; // one TripleRand instance 0161 0162 }; // TripleRand 0163 0164 } // namespace CLHEP 0165 0166 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 0167 // backwards compatibility will be enabled ONLY in CLHEP 1.9 0168 using namespace CLHEP; 0169 #endif 0170 0171 #endif // TripleRand_h
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |