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

RandomObjects/CLHEP/Random/RandEngine.h
Go to the documentation of this file.
1// $Id: RandEngine.h,v 1.6 2010/06/16 17:24:53 garren Exp $
2// -*- C++ -*-
3//
4// -----------------------------------------------------------------------
5// HEP Random
6// --- RandEngine ---
7// class header file
8// -----------------------------------------------------------------------
9// This file is part of Geant4 (simulation toolkit for HEP).
10//
11// Simple random engine using rand() and srand() functions from C standard
12// library to implement the flat() basic distribution and for setting
13// seeds.
14// Copy constructor and operator= are private for objects of this class.
15
16// =======================================================================
17// Gabriele Cosmo - Created: 5th September 1995
18// - Minor corrections: 31st October 1996
19// - Added methods for engine status: 19th November 1996
20// - setSeed(), setSeeds() now have default dummy argument
21// set to zero: 11th July 1997
22// - Private copy constructor and operator=: 26th Feb 1998
23// J.Marraffino - Added stream operators and related constructor.
24// Added automatic seed selection from seed table and
25// engine counter: 15th Feb 1998
26// Ken Smith - Added conversion operators: 6th Aug 1998
27// replace mx by mantissa_bit_32
28// M Fischler - Inserted warnings about the fact that the quality of rand()
29// is quite poor.
30// Mark Fischler Methods for distrib. instance save/restore 12/8/04
31// Mark Fischler methods for anonymous save/restore 12/27/04
32// =======================================================================
33
34#ifndef RandEngine_h
35#define RandEngine_h 1
36
37#include "CLHEP/Random/defs.h"
38#include "CLHEP/Random/RandomEngine.h"
39
40namespace CLHEP {
41
46class RandEngine : public HepRandomEngine {
47
48public:
49
50 RandEngine(std::istream& is);
52 RandEngine(long seed);
53 RandEngine(int rowIndex, int colIndex);
54 virtual ~RandEngine();
55 // Constructors and destructor
56
57 double flat();
58 // It returns a pseudo random number between 0 and 1,
59 // according to the standard stdlib random function rand()
60 // but excluding the end points.
61 //
62 // WARNING: rand() is quite a weak generator on most systems, <
63 // will not pass several randomness tests, and does not give a <
64 // reproducible sequence of numbers. <
65
66 void flatArray (const int size, double* vect);
67 // Fills the array "vect" of specified size with flat random values.
68
69 void setSeed(long seed, int dum=0);
70 // Sets the state of the algorithm according to seed.
71
72 void setSeeds(const long * seeds, int dum=0);
73 // Sets the state of the algorithm according to the zero terminated
74 // array of seeds. Only the first seed is used.
75
76 void saveStatus( const char filename[] = "Rand.conf" ) const;
77 // Saves on file Rand.conf the current engine status.
78 // WARNING: This is non-functional, as rand() on various systems will <
79 // not give reproducible streams. <
80
81 void restoreStatus( const char filename[] = "Rand.conf" );
82 // Reads from file Rand.conf the last saved engine status
83 // and restores it.
84 // WARNING: This is non-functional, as rand() on various systems will <
85 // not give reproducible streams. <
86
87 void showStatus() const;
88 // Dumps the engine status on the screen.
89
90 operator unsigned int(); // 32-bit flat value, quickest of all.
91
92 virtual std::ostream & put (std::ostream & os) const;
93 virtual std::istream & get (std::istream & is);
94 static std::string beginTag ( );
95 virtual std::istream & getState ( std::istream & is );
96
97 std::string name() const;
98 static std::string engineName() {return "RandEngine";}
99
100 std::vector<unsigned long> put () const;
101 bool get (const std::vector<unsigned long> & v);
102 bool getState (const std::vector<unsigned long> & v);
103
104 static const unsigned int VECTOR_STATE_SIZE = 3;
105
106private:
107
108 RandEngine(const RandEngine &p);
109 RandEngine & operator = (const RandEngine &p);
110 // Private copy constructor and assignment operator.
111
112private:
113
114 long seq;
115 static int numEngines;
116 static int maxIndex;
117
118};
119
120} // namespace CLHEP
121
122#ifdef ENABLE_BACKWARDS_COMPATIBILITY
123// backwards compatibility will be enabled ONLY in CLHEP 1.9
124using namespace CLHEP;
125#endif
126
127#endif
bool getState(const std::vector< unsigned long > &v)
RandEngine(int rowIndex, int colIndex)
void flatArray(const int size, double *vect)
RandEngine(std::istream &is)
RandEngine(long seed)
void saveStatus(const char filename[]="Rand.conf") const
static const unsigned int VECTOR_STATE_SIZE
void setSeed(long seed, int dum=0)
std::vector< unsigned long > put() const
std::string name() const
void restoreStatus(const char filename[]="Rand.conf")
virtual ~RandEngine()
virtual std::istream & get(std::istream &is)
virtual std::ostream & put(std::ostream &os) const
void showStatus() const
bool get(const std::vector< unsigned long > &v)
virtual std::istream & getState(std::istream &is)
static std::string beginTag()
void setSeeds(const long *seeds, int dum=0)