CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

DualRand.h

Go to the documentation of this file.
00001 // $Id: DualRand.h,v 1.3.4.2 2005/04/15 16:32:52 garren Exp $
00002 // -*- C++ -*-
00003 //
00004 // -----------------------------------------------------------------------
00005 //                           Hep Random
00006 //                        --- DualRand ---
00007 //                        class header file
00008 // -----------------------------------------------------------------------
00009 //                                                                      
00010 //  Canopy random number generator DualRand
00011 //      Re-written as C++ routine for 32-bit ints MF 1/26/98
00012 //
00013 //  Exclusive or of a feedback shift register and integer congruence
00014 //  random number generator.  The feedback shift register uses offsets
00015 //  127 and 97.  The integer congruence generator uses a different
00016 //  multiplier for each stream.  The multipliers are chosen to give
00017 //  full period and maximum "potency" for modulo 2^32.  The period of
00018 //  the combined random number generator is 2^159 - 2^32, and the
00019 //  sequences are different for each stream (not just started in a
00020 //  different place).
00021 //
00022 // =======================================================================
00023 //  Canopy random number generator DualRand.
00024 //  Doug Toussaint   5/25/88                                               
00025 //  Optimized by GMH 7/26/88                                               
00026 //  Optimized by GMH 7/26/88                                               
00027 //  Repaired  by GMH 12/1/88 to update modular congruence state            
00028 //  Put into ranlib by GMH 6/23/89                                         
00029 //  Re-written as C++ routine for 32-bit ints MF 1/26/98                   
00030 //  Re-written for CLHEP package             KLS 6/04/98                   
00031 //  Removed pow() from flat method for speed KLS 7/21/98                   
00032 //  Ken Smith      - Added conversion operators:  6th Aug 1998             
00033 //  Mark Fischler    methods for distrib. instance save/restore 12/8/04    
00034 //  Mark Fischler    methods for anonymous save/restore 12/27/04    
00035 // Mark Fischler  - methods for vector save/restore 3/7/05    
00036 // =======================================================================
00037 
00038 
00039 #ifndef DualRand_h
00040 #define DualRand_h
00041 
00042 #include "CLHEP/Random/defs.h"
00043 #include "CLHEP/Random/RandomEngine.h"
00044 
00045 namespace CLHEP {
00046 
00051 class DualRand: public HepRandomEngine {
00052 
00053 public:
00054 
00055   DualRand();
00056   DualRand(long seed);
00057   DualRand(std::istream & is);
00058   DualRand(int rowIndex, int colIndex);
00059   virtual ~DualRand();
00060 
00061   DualRand(const DualRand & p);
00062   DualRand & operator=(const DualRand & p);
00063 
00064   double flat();
00065   // Returns a pseudo random number between 0 and 1 
00066   // (excluding the end points)
00067 
00068   void flatArray(const int size, double * vect);
00069   // Fills an array "vect" of specified size with flat random values.
00070 
00071   void setSeed(long seed, int);
00072   // Sets the state of the algorithm according to seed.
00073 
00074   void setSeeds(const long * seeds, int);
00075   // Sets the state of the algorithm according to the zero-terminated 
00076   // array of seeds.
00077 
00078   void saveStatus( const char filename[] = "DualRand.conf") const;
00079   // Saves on named file the current engine status.
00080 
00081   void restoreStatus( const char filename[] = "DualRand.conf" );
00082   // Reads from named file the last saved engine status and restores it.
00083 
00084   void showStatus() const;
00085   // Dumps the current engine status on the screen.
00086 
00087   operator float();      // flat value, without worrying about filling bits
00088   operator unsigned int();  // 32-bit flat value, quickest of all
00089 
00090   virtual std::ostream & put (std::ostream & os) const;
00091   virtual std::istream & get (std::istream & is);
00092   static  std::string beginTag ( );
00093   virtual std::istream & getState ( std::istream & is );
00094     
00095   std::string name() const;
00096   static std::string engineName() {return "DualRand";}
00097 
00098   std::vector<unsigned long> put () const;
00099   bool get (const std::vector<unsigned long> & v);
00100   bool getState (const std::vector<unsigned long> & v);
00101   
00102   static const unsigned int VECTOR_STATE_SIZE = 9;
00103 
00104 private:
00105 
00106   static int numEngines;
00107 
00108   static double twoToMinus_32;
00109   static double twoToMinus_53;
00110   static double nearlyTwoToMinus_54;
00111   void powersOfTwo();
00112 
00113   // This generator is composed of two others combined:
00114 
00115   class Tausworthe {
00116   public:
00117     Tausworthe();
00118     Tausworthe(unsigned int seed);
00119     operator unsigned int();
00120     void put(std::ostream & os) const;
00121     void put(std::vector<unsigned long> & v) const;
00122     void get(std::istream & is);
00123     bool get(std::vector<unsigned long>::const_iterator & iv);
00124   private:
00125     int wordIndex;
00126     unsigned int words[4];
00127   }; // Tausworthe
00128 
00129   class IntegerCong {
00130   public:
00131     IntegerCong();
00132     IntegerCong(unsigned int seed, int streamNumber);
00133     operator unsigned int();
00134     void put(std::ostream & os) const;
00135     void put(std::vector<unsigned long> & v) const;
00136     void get(std::istream & is);
00137     bool get(std::vector<unsigned long>::const_iterator & iv);
00138   private:
00139     unsigned int state, multiplier, addend;
00140   }; // IntegerCong
00141 
00142   Tausworthe  tausworthe;
00143   IntegerCong integerCong;
00144 
00145 }; // DualRand
00146 
00147 }  // namespace CLHEP
00148 
00149 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
00150 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
00151 using namespace CLHEP;
00152 #endif
00153 
00154 #endif // DualRand_h

Generated on Thu Jul 1 22:02:30 2010 for CLHEP by  doxygen 1.4.7