GammaLib 2.0.0
Loading...
Searching...
No Matches
GRan.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GRan.hpp - Random number generator class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2011-2014 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21/**
22 * @file GRan.hpp
23 * @brief Random number generator class definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GRAN_HPP
28#define GRAN_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <string>
32#include <vector>
33#include "GBase.hpp"
34#include "GVector.hpp"
35
36
37/***********************************************************************//**
38 * @class GRan
39 *
40 * @brief Random number generator class
41 *
42 * This class implements a random number generator.
43 ***************************************************************************/
44class GRan : public GBase {
45
46public:
47 // Constructors and destructors
48 GRan(void);
49 GRan(unsigned long long int seed);
50 GRan(const GRan& ran);
51 virtual ~GRan(void);
52
53 // Operators
54 GRan& operator=(const GRan& ran);
55
56 // Methods
57 void clear(void);
58 GRan* clone(void) const;
59 std::string classname(void) const;
60 void seed(unsigned long long int seed);
61 unsigned long long int seed(void) const;
62 unsigned long int int32(void);
63 unsigned long long int int64(void);
64 double uniform(void);
65 double normal(void);
66 double exp(const double& lambda);
67 double poisson(const double& lambda);
68 double chisq2(void);
69 int cdf(const std::vector<double>& cdf);
70 int cdf(const GVector& cdf);
71 std::string print(const GChatter& chatter = NORMAL) const;
72
73protected:
74 // Protected methods
75 void init_members(unsigned long long int seed = 41L);
76 void copy_members(const GRan& ran);
77 void free_members(void);
78
79 // Protected data members
80 unsigned long long int m_seed; //!< Random number generator seed
81 unsigned long long int m_value1; //!< Value 1
82 unsigned long long int m_value2; //!< Value 2
83 unsigned long long int m_value3; //!< Value 3
84
85 // Poisson cache
86 double m_old_lambda; //!< Old lambda value
87 double m_sqrt_lambda; //!< sqrt(2*lambda)
88 double m_log_lambda; //!< log(lambda)
89 double m_exp_lambda; //!< exp(-lambda)
90};
91
92
93/***********************************************************************//**
94 * @brief Return class name
95 *
96 * @return String containing the class name ("GRan").
97 ***************************************************************************/
98inline
99std::string GRan::classname(void) const
100{
101 return ("GRan");
102}
103
104
105/***********************************************************************//**
106 * @brief Return seed value
107 *
108 * @return Seed value.
109 ***************************************************************************/
110inline
111unsigned long long int GRan::seed(void) const
112{
113 return m_seed;
114}
115
116#endif /* GRAN_HPP */
Definition of interface for all GammaLib classes.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Vector class interface definition.
Interface class for all GammaLib classes.
Definition GBase.hpp:52
Random number generator class.
Definition GRan.hpp:44
GRan * clone(void) const
Clone random number generator.
Definition GRan.cpp:176
unsigned long long int int64(void)
Return 64-bit random unsigned integer.
Definition GRan.cpp:216
double m_sqrt_lambda
sqrt(2*lambda)
Definition GRan.hpp:87
unsigned long long int m_value1
Value 1.
Definition GRan.hpp:81
unsigned long long int seed(void) const
Return seed value.
Definition GRan.hpp:111
double normal(void)
Returns normal deviates.
Definition GRan.cpp:257
std::string print(const GChatter &chatter=NORMAL) const
Print random number generator information.
Definition GRan.cpp:451
unsigned long long int m_value2
Value 2.
Definition GRan.hpp:82
double m_log_lambda
log(lambda)
Definition GRan.hpp:88
unsigned long int int32(void)
Return 32-bit random unsigned integer.
Definition GRan.cpp:206
double chisq2(void)
Returns Chi2 deviates for 2 degrees of freedom.
Definition GRan.cpp:370
void clear(void)
Clear random number generator.
Definition GRan.cpp:158
double uniform(void)
Returns random double precision floating value in range 0 to 1.
Definition GRan.cpp:242
void free_members(void)
Delete class members.
Definition GRan.cpp:533
unsigned long long int m_seed
Random number generator seed.
Definition GRan.hpp:80
GRan(void)
Void constructor.
Definition GRan.cpp:57
int cdf(const std::vector< double > &cdf)
Random sampling from a cumulative density function.
Definition GRan.cpp:390
void init_members(unsigned long long int seed=41L)
Initialise class members.
Definition GRan.cpp:484
std::string classname(void) const
Return class name.
Definition GRan.hpp:99
double exp(const double &lambda)
Returns exponential deviates.
Definition GRan.cpp:291
unsigned long long int m_value3
Value 3.
Definition GRan.hpp:83
void copy_members(const GRan &ran)
Copy class members.
Definition GRan.cpp:513
GRan & operator=(const GRan &ran)
Assignment operator.
Definition GRan.cpp:125
double m_exp_lambda
exp(-lambda)
Definition GRan.hpp:89
double poisson(const double &lambda)
Returns Poisson deviates.
Definition GRan.cpp:316
virtual ~GRan(void)
Destructor.
Definition GRan.cpp:103
double m_old_lambda
Old lambda value.
Definition GRan.hpp:86
Vector class.
Definition GVector.hpp:46