TF++, Miscellaneous classes and modules in C++:
rng.h
Go to the documentation of this file.
1 
36 // include guard
37 #ifndef TF_RNG_H_VERSION
38 
39 #define TF_RNG_H_VERSION \
40  "TF_RNG_H V1.1"
41 
42 #include <tfxx/error.h>
43 #include <ostream>
44 #include <string>
45 #include <gsl/gsl_rng.h>
46 #include <gsl/gsl_randist.h>
47 
54 namespace tfxx {
55 
61  namespace numeric {
62 
63  /* ---------------------------------------------------------------------- */
64 
78  class RNGgaussian {
79  public:
81  explicit RNGgaussian(const double& std=1.,
82  const double& mean=0.,
83  const char* type="default");
84  ~RNGgaussian();
86  double operator()() const;
88  double value() const;
90  void set(const unsigned long int& seed);
92  void set();
94  std::string type() const {return std::string(MR->type->name); }
96  unsigned long int seed() const { return Mseed; }
98  double std() const { return Mstd; }
100  double mean() const { return Mmean; }
102  static void rng_list_types(std::ostream& os);
104  static const char* comment_gsl_rng_ranlux;
105  private:
107  double Mstd, Mmean;
109  gsl_rng* MR;
111  unsigned long int Mseed;
112  public:
119  {
120  public:
124  UTException(const char* type,
125  const char* file,
126  const int& line,
127  const char* condition);
129  virtual ~UTException() { }
130  private:
132  const char* Mtype;
133  }; // class UTException
134  }; // class RNGgaussian
135  } // namespace numeric
136 
137 } // namespace tfxx
138 
139 #endif // TF_RNG_H_VERSION (includeguard)
140 
141 /* ----- END OF rng.h ----- */
RNGgaussian(const double &std=1., const double &mean=0., const char *type="default")
initialize random number generator
Definition: rng.cc:52
tfxx::error::Exception TBase
base class
Definition: rng.h:122
STL namespace.
virtual ~UTException()
provide explicit virtual destructor
Definition: rng.h:129
UTException(const char *type, const char *file, const int &line, const char *condition)
Create with message, failed assertion, and code position.
Definition: rng.cc:137
double Mstd
store standard deviation and mean value
Definition: rng.h:107
double mean() const
return mean
Definition: rng.h:100
double value() const
returns a random number
Definition: rng.cc:92
unsigned long int seed() const
return last seed value
Definition: rng.h:96
std::string type() const
return type of random number generator
Definition: rng.h:94
const char * Mtype
pointer name string of requested RNG type
Definition: rng.h:132
static void rng_list_types(std::ostream &os)
print list of random number generators to stream.
Definition: rng.cc:122
exception class for RNG indicating request for unkown type
Definition: rng.h:118
unsigned long int Mseed
memorize last seed value
Definition: rng.h:111
Provide random numbers with Gaussian distribution.This class is an interface to the GSL random number...
Definition: rng.h:78
static const char * comment_gsl_rng_ranlux
comment on GSL RNGs
Definition: rng.h:104
double operator()() const
returns a random number
Definition: rng.cc:98
double std() const
return standard deviation
Definition: rng.h:98
Base class for exceptions.
Definition: error.h:78
gsl_rng * MR
pointer to RNG
Definition: rng.h:109
Namespace containing all code of library libtfxx.