Changeset 364
- Timestamp:
- Aug 5, 2005, 10:25:21 AM (18 years ago)
- Location:
- trunk/lib/utility
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/utility/Random.h
r362 r364 57 57 public: 58 58 59 inline double operator()(void) const { return gsl_rng_uniform(rng_->rng()); } 60 61 }; 62 63 64 59 inline double operator()(void) const { return gsl_rng_uniform(rng_->rng());} 60 61 }; 62 63 /// 64 /// Class to generate Gaussian random numbers. 65 /// 65 66 class RandomGaussian : public RandomContinuous 66 67 { … … 83 84 }; 84 85 85 86 class RandomDiscrete { 87 }; 88 89 90 class RandomDiscreteUniform : public RandomDiscrete { 86 /// 87 /// @brief exponential 88 /// 89 class RandomExponential : public RandomContinuous 90 { 91 public: 92 /// 93 /// Constructor 94 /// 95 inline RandomExponential(const double m=1) 96 : m_(m){} 97 98 /// 99 /// 100 /// 101 inline double operator()(void) const 102 { return gsl_ran_exponential(rng_->rng(), m_); } 103 104 /// 105 /// 106 /// 107 inline double operator()(const double m) const 108 { return gsl_ran_exponential(rng_->rng(), m); } 109 110 private: 111 double m_; 112 }; 113 114 115 /// 116 /// Base class for discrete random distributions. 117 /// 118 class RandomDiscrete 119 { 120 public: 121 /// 122 /// Constructor 123 /// 124 inline RandomDiscrete(void) { rng_=RNG::instance(89); } 125 126 /// 127 /// Common interface for all Discrete Random Classes 128 /// 129 virtual long operator()(void) const = 0; 130 131 protected: 132 RNG* rng_; 133 }; 134 135 136 class RandomDiscreteUniform : public RandomDiscrete 137 { 138 public: 139 /// 140 /// Constructor. 141 /// 142 inline RandomDiscreteUniform(const u_long range, const long min=0) 143 : min_(min), range_(range) {} 144 145 /// 146 /// @return A random number between \a min_ and \a range_ - \a min_ 147 /// 148 inline long operator()(void) const 149 { return gsl_rng_uniform_int(rng_->rng(), range_)+min_; } 150 151 /// 152 /// @return A random number between 0 and \a range. 153 /// 154 inline long operator()(const u_long range) const 155 { return gsl_rng_uniform_int(rng_->rng(), range); } 156 157 /// 158 /// @return A random number between \a min and \a range - \a min 159 /// 160 inline long operator()(const u_long range, const long min) const 161 { return gsl_rng_uniform_int(rng_->rng(), range)+min; } 162 163 164 private: 165 long min_; 166 u_long range_; 167 }; 168 169 170 /// 171 /// @brief Poisson 172 /// 173 class RandomPoisson : public RandomContinuous 174 { 175 public: 176 /// 177 /// Constructor 178 /// 179 inline RandomPoisson(const double m=1) 180 : m_(m){} 181 182 /// 183 /// 184 /// 185 inline double operator()(void) const 186 { return gsl_ran_poisson(rng_->rng(), m_); } 187 188 /// 189 /// 190 /// 191 inline double operator()(const double m) const 192 { return gsl_ran_poisson(rng_->rng(), m); } 193 194 private: 195 double m_; 91 196 }; 92 197 -
trunk/lib/utility/random_singleton.cc
r358 r364 2 2 3 3 #include <c++_tools/utility/random_singleton.h> 4 5 #include <c++_tools/gslapi/vector.h> 4 6 5 7 namespace theplu { … … 55 57 } 56 58 57 /** 58 double random_singleton::get_poisson(const double m) const 59 void random_singleton::general_distribution_prob(const gslapi::vector& p) 59 60 { 60 61 61 62 } 62 */63 63 64 64 }} // of namespace utility and namespace theplu -
trunk/lib/utility/random_singleton.h
r359 r364 13 13 14 14 namespace theplu { 15 namespace gslapi { 16 class vector; 17 } 18 15 19 namespace utility { 16 20 17 21 /// 18 22 /// Class defining interface for different random stuff. 19 23 /// … … 111 115 /// @see rnd_discrete 112 116 /// 113 inline void general_distribution_prob( const size_t& k, 114 const double* p ) 115 { gen_ = gsl_ran_discrete_preproc( k, p ); } 117 void general_distribution_prob( const gslapi::vector& p); 116 118 117 119 ///
Note: See TracChangeset
for help on using the changeset viewer.