Changeset 425 for trunk/lib/random/random.h
- Timestamp:
- Dec 7, 2005, 3:14:24 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/random/random.h
r424 r425 47 47 /// documentation. 48 48 /// 49 /// @todo Is this class properly implemented? The underlying random 50 /// number genereator should be a singleton, while allowing for 51 /// several different distribution to be used. Jari's feeling is 52 /// that the current implementation restricts the use to only one 53 /// distribution per binary! 49 /// @todo Get those exceptions in! Should classes be considered 50 /// const if underlying structures are changed such as GSL stuff? 54 51 /// 55 52 class RNG … … 60 57 61 58 /// 62 /// @brief Get an instance of the random number 63 /// generator/distribution. 59 /// Get an instance of the random number generator. If the random 60 /// number generator is not already created, the call will create 61 /// a new generator and use the default seed. I needed, the seed 62 /// must be changed with the seed or seed_from_devurandom member 63 /// functions. 64 /// 65 /// @brief Get an instance of the random number generator. 64 66 /// 65 67 /// @return A pointer to the random number generator. 66 68 /// 67 static RNG* instance(u_long seed=0) 68 { if (!instance_) instance_=new RNG(seed); return instance_; } 69 /// @see seed and seed_from_devurandom 70 /// 71 static RNG* instance(void) 72 { if (!instance_) instance_=new RNG; return instance_; } 69 73 70 74 /// … … 106 110 107 111 private: 108 RNG( u_long seed);112 RNG(void); 109 113 110 114 static RNG* instance_; … … 122 126 /// with its probability. 123 127 /// 124 class Discrete 128 class Discrete 125 129 { 126 130 public: … … 129 133 /// 130 134 inline Discrete(void) { rng_=RNG::instance(); } 135 136 /// 137 /// Set the seed to \a s in the underlying rng. If \a s is zero, a 138 /// default value from the rng's original implementation is used 139 /// (cf. GSL documentation). 140 /// 141 /// @brief Set the seed to \a s. 142 /// 143 /// @see seed_from_devurandom, RNG::seed_from_devurandom, RNG::seed 144 /// 145 inline void seed(u_long s) const { rng_->seed(s); } 146 147 /// 148 /// @brief Set the seed using the /dev/urandom device. 149 /// 150 /// @return The seed acquired from /dev/urandom. 151 /// 152 /// @see seed, RNG::seed_from_devurandom, RNG::seed 153 /// 154 u_long seed_from_devurandom(void) { return rng_->seed_from_devurandom(); } 131 155 132 156 /// … … 190 214 /// @brief Default constructor. 191 215 /// 192 DiscreteUniform(void) : range_(rng_->max() +1) {}216 DiscreteUniform(void) : range_(rng_->max()) {} 193 217 194 218 /// 195 219 /// @brief Constructor. 196 220 /// 197 /// @param n sets the range. Object will generate integers from 198 /// [0,n-1]. 221 /// The generator will generate integers from \f$ [0,n-1] \f$. If 222 /// \a n is larger than the maximum number the random number 223 /// generator can return, then (currently) \a n is adjusted 224 /// appropriately. 225 /// 226 /// @todo If a too large \a n is given an exception should be 227 /// thrown, i.e. the behaviour of this class will change. The case 228 /// when argument is 0 is not treated gracefully (underlying GSL 229 /// functionality will not return). 199 230 /// 200 231 DiscreteUniform(const u_long n) : range_(n) 201 { if ( range_ -1>rng_->max() ) range_=rng_->max()+1; }232 { if ( range_>rng_->max() ) range_=rng_->max(); } 202 233 203 234 /// … … 281 312 282 313 /// 314 /// Set the seed to \a s in the underlying rng. If \a s is zero, a 315 /// default value from the rng's original implementation is used 316 /// (cf. GSL documentation). 317 /// 318 /// @brief Set the seed to \a s. 319 /// 320 /// @see seed_from_devurandom, RNG::seed_from_devurandom, RNG::seed 321 /// 322 inline void seed(u_long s) const { rng_->seed(s); } 323 324 /// 325 /// @brief Set the seed using the /dev/urandom device. 326 /// 327 /// @return The seed acquired from /dev/urandom. 328 /// 329 /// @see seed, RNG::seed_from_devurandom, RNG::seed 330 /// 331 u_long seed_from_devurandom(void) { return rng_->seed_from_devurandom(); } 332 333 /// 283 334 /// @return A random number 284 335 ///
Note: See TracChangeset
for help on using the changeset viewer.