Ignore:
Timestamp:
Aug 8, 2005, 4:39:24 PM (17 years ago)
Author:
Peter
Message:

removed min parameter in uniform_int and added test to rnd_test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/random/random.h

    r378 r379  
    2727  /// There are many different rng's available in GSL. Currently only
    2828  /// the default generator is implemented and no other one is
    29   /// choosable though the class interface. This means that you have
     29  /// choosable through the class interface. This means that you have
    3030  /// to fall back to the use of environment variables as described in
    3131  /// the GSL documentation, or be bold and request support for other
     
    251251    /// @return A random number.
    252252    ///
    253     virtual long operator()(void) const = 0;
     253    virtual u_long operator()(void) const = 0;
    254254   
    255255  protected:
     
    262262  /// Discrete uniform distribution also known as the "equally likely
    263263  /// 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.
    265265  ///
    266266  /// Distribution function \f$ p(k) = \frac{1}{b-a} \f$ for \f$ a \le
    267267  /// k < b \f$ \n
    268   /// Expectation value: \f$ \frac{a+b}{2} \f$ \n
     268  /// Expectation value: \f$ \frac{a+b-1}{2} \f$ \n
    269269  /// Variance: \f$ \frac{1}{3}((b-a)^2-1) \f$
    270270  ///
     
    276276    /// @brief Constructor.
    277277    ///
    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);
    283279
    284280    ///
    285281    /// @brief Constructor.
    286282    ///
    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:
    317310    u_long range_;
    318311  };
     
    347340    /// @return A Poisson distributed number.
    348341    ///
    349     inline long operator()(void) const
     342    inline u_long operator()(void) const
    350343    { return gsl_ran_poisson(rng_->rng(), m_); }
    351344
     
    387380    /// @return A random number.
    388381    ///
    389     inline long operator()(void) const
     382    inline u_long operator()(void) const
    390383    { return gsl_ran_discrete(rng_->rng(), gen_); }
    391384
Note: See TracChangeset for help on using the changeset viewer.