00001 /*************************************************************************** 00002 * GRan.hpp - Random number generator class * 00003 * ----------------------------------------------------------------------- * 00004 * copyright (C) 2011-2014 by Juergen Knoedlseder * 00005 * ----------------------------------------------------------------------- * 00006 * * 00007 * This program is free software: you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation, either version 3 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 * This program is distributed in the hope that it will be useful, * 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00015 * GNU General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU General Public License * 00018 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00019 * * 00020 ***************************************************************************/ 00021 /** 00022 * @file GRan.hpp 00023 * @brief Random number generator class definition 00024 * @author Juergen Knoedlseder 00025 */ 00026 00027 #ifndef GRAN_HPP 00028 #define GRAN_HPP 00029 00030 /* __ Includes ___________________________________________________________ */ 00031 #include <string> 00032 #include <vector> 00033 #include "GBase.hpp" 00034 #include "GVector.hpp" 00035 00036 00037 /***********************************************************************//** 00038 * @class GRan 00039 * 00040 * @brief Random number generator class 00041 * 00042 * This class implements a random number generator. 00043 ***************************************************************************/ 00044 class GRan : public GBase { 00045 00046 public: 00047 // Constructors and destructors 00048 GRan(void); 00049 GRan(unsigned long long int seed); 00050 GRan(const GRan& ran); 00051 virtual ~GRan(void); 00052 00053 // Operators 00054 GRan& operator=(const GRan& ran); 00055 00056 // Methods 00057 void clear(void); 00058 GRan* clone(void) const; 00059 std::string classname(void) const; 00060 void seed(unsigned long long int seed); 00061 unsigned long long int seed(void) const; 00062 unsigned long int int32(void); 00063 unsigned long long int int64(void); 00064 double uniform(void); 00065 double normal(void); 00066 double exp(const double& lambda); 00067 double poisson(const double& lambda); 00068 double chisq2(void); 00069 int cdf(const std::vector<double>& cdf); 00070 int cdf(const GVector& cdf); 00071 std::string print(const GChatter& chatter = NORMAL) const; 00072 00073 protected: 00074 // Protected methods 00075 void init_members(unsigned long long int seed = 41L); 00076 void copy_members(const GRan& ran); 00077 void free_members(void); 00078 00079 // Protected data members 00080 unsigned long long int m_seed; //!< Random number generator seed 00081 unsigned long long int m_value1; //!< Value 1 00082 unsigned long long int m_value2; //!< Value 2 00083 unsigned long long int m_value3; //!< Value 3 00084 00085 // Poisson cache 00086 double m_old_lambda; //!< Old lambda value 00087 double m_sqrt_lambda; //!< sqrt(2*lambda) 00088 double m_log_lambda; //!< log(lambda) 00089 double m_exp_lambda; //!< exp(-lambda) 00090 }; 00091 00092 00093 /***********************************************************************//** 00094 * @brief Return class name 00095 * 00096 * @return String containing the class name ("GRan"). 00097 ***************************************************************************/ 00098 inline 00099 std::string GRan::classname(void) const 00100 { 00101 return ("GRan"); 00102 } 00103 00104 00105 /***********************************************************************//** 00106 * @brief Return seed value 00107 * 00108 * @return Seed value. 00109 ***************************************************************************/ 00110 inline 00111 unsigned long long int GRan::seed(void) const 00112 { 00113 return m_seed; 00114 } 00115 00116 #endif /* GRAN_HPP */