// RandomGenerator.h #ifndef RandomGenerator_H #define RandomGenerator_H // A generator produces objects with random parameters. // // This class is abstract and contains the interface for // the random number generator. Each instance will maintain // its own sequence of random numbers. // // We use the default CLHEP random number generator. // // The calls to rand are encapsulated so that we can keep count of // the number of calls to reproduce the state. #include #include class RandomGenerator { private: // attributes // Random number generator. RanluxEngine _rand; // Number of calls since seed was set. int _ncall; private: // methods // Hide assignment operator. RandomGenerator& operator=(const RandomGenerator& rhs); // Set the state = seed and number of calls. void set_state(long seed, int ncall); protected: // Return a flat value in range (min.max). double flat(double min, double max); // Return according to Gaussian distribution with sigma = 1.0. double gauss(); // Output stream. virtual void ostr(std::ostream& stream) const; // Raw output stream. // Does not include begin and end object delimiters. virtual void raw_ostr(std::ostream& stream) const; public: // Default constructor. RandomGenerator(); // Constructor from seed. RandomGenerator(long seed); // Copy constructor. // The new generator is independent from the original and is in the // same state. RandomGenerator(const RandomGenerator& rhs); // Destructor. virtual ~RandomGenerator(); // Set the seed. // Generator is positioned at the beginning of the sequence. void set_seed(long seed); // Set the state (seed + ncall) to be the same as that of the argument. void set_state(const RandomGenerator& gen); // output stream friend std::ostream& operator<<(std::ostream& stream, const RandomGenerator& rgen); }; #endif