Changeset 379 for trunk/lib/random/random.h
- Timestamp:
- Aug 8, 2005, 4:39:24 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/random/random.h
r378 r379 27 27 /// There are many different rng's available in GSL. Currently only 28 28 /// the default generator is implemented and no other one is 29 /// choosable th ough the class interface. This means that you have29 /// choosable through the class interface. This means that you have 30 30 /// to fall back to the use of environment variables as described in 31 31 /// the GSL documentation, or be bold and request support for other … … 251 251 /// @return A random number. 252 252 /// 253 virtual long operator()(void) const = 0;253 virtual u_long operator()(void) const = 0; 254 254 255 255 protected: … … 262 262 /// Discrete uniform distribution also known as the "equally likely 263 263 /// outcomes" distribution. Each outcome, in this case an integer 264 /// from \f$ [a,b) \f$, have equal probability to occur.264 /// from [a,b) , have equal probability to occur. 265 265 /// 266 266 /// Distribution function \f$ p(k) = \frac{1}{b-a} \f$ for \f$ a \le 267 267 /// k < b \f$ \n 268 /// Expectation value: \f$ \frac{a+b }{2} \f$ \n268 /// Expectation value: \f$ \frac{a+b-1}{2} \f$ \n 269 269 /// Variance: \f$ \frac{1}{3}((b-a)^2-1) \f$ 270 270 /// … … 276 276 /// @brief Constructor. 277 277 /// 278 /// @todo The default behaviour of the underlying RNG should be 279 /// setup when this constructor is used. 280 /// 281 inline DiscreteUniform(void) 282 : min_(0), range_(0) {} 278 DiscreteUniform(void); 283 279 284 280 /// 285 281 /// @brief Constructor. 286 282 /// 287 /// @param \a range is number of different integers that can be 288 /// generated \f$ (b-a+1) \f$ \a min is the minimal integer that 289 /// can be generated \f$ (a) \f$ 290 /// 291 inline DiscreteUniform(const u_long range, const long min=0) 292 : min_(min), range_(range) {} 293 294 /// 295 /// @return A random number between \a min_ and \a range_ - \a min_ 296 /// 297 inline long operator()(void) const 298 { return gsl_rng_uniform_int(rng_->rng(), range_)+min_; } 299 300 /// 301 /// @return A random number between 0 and \a range. 302 /// 303 /// @note This operator ignores any set minimum range parameter. 304 /// 305 inline long operator()(const u_long range) const 306 { return gsl_rng_uniform_int(rng_->rng(), range); } 307 308 /// 309 /// @return A random number between \a min and \a range - \a min 310 /// 311 inline long operator()(const u_long range, const long min) const 312 { return gsl_rng_uniform_int(rng_->rng(), range)+min; } 313 314 315 private: 316 long min_; 283 /// @param n sets the range. Object will generate integers from 284 /// [0,n-1]. 285 /// 286 /// @todo exception should be thrown, when n is out of range 287 /// 288 DiscreteUniform(const u_long n); 289 290 /// 291 /// This function returns a random integer from 0 to n-1 292 /// inclusive. All integers in the range [0,n-1] are equally 293 /// likely. n is set in constructor. 294 /// 295 inline u_long operator()(void) const 296 { return gsl_rng_uniform_int(rng_->rng(), range_); } 297 298 /// 299 /// This function returns a random integer from 0 to n-1 300 /// inclusive. All integers in the range [0,n-1] are equally 301 /// likely. 302 /// 303 /// @todo exception should be thrown, when n is out of range 304 /// 305 inline u_long operator()(const u_long n) const 306 { return gsl_rng_uniform_int(rng_->rng(), n); } 307 308 309 private: 317 310 u_long range_; 318 311 }; … … 347 340 /// @return A Poisson distributed number. 348 341 /// 349 inline long operator()(void) const342 inline u_long operator()(void) const 350 343 { return gsl_ran_poisson(rng_->rng(), m_); } 351 344 … … 387 380 /// @return A random number. 388 381 /// 389 inline long operator()(void) const382 inline u_long operator()(void) const 390 383 { return gsl_ran_discrete(rng_->rng(), gen_); } 391 384
Note: See TracChangeset
for help on using the changeset viewer.