Changeset 1271 for trunk/yat/random


Ignore:
Timestamp:
Apr 9, 2008, 6:11:07 PM (13 years ago)
Author:
Peter
Message:

replaced u_int with unsigned int or size_t

Location:
trunk/yat/random
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/random/random.cc

    r1000 r1271  
    6161
    6262
    63   u_long RNG::max(void) const
     63  unsigned long RNG::max(void) const
    6464  {
    6565    return gsl_rng_max(rng_);
     
    6767
    6868
    69   u_long RNG::min(void) const
     69  unsigned long RNG::min(void) const
    7070  {
    7171    return gsl_rng_min(rng_);
     
    8585
    8686
    87   void RNG::seed(u_long s) const
     87  void RNG::seed(unsigned long s) const
    8888  {
    8989    gsl_rng_set(rng_,s);
     
    9191
    9292
    93   u_long RNG::seed_from_devurandom(void)
    94   {
    95     u_char ulongsize=sizeof(u_long);
     93  unsigned long RNG::seed_from_devurandom(void)
     94  {
     95    unsigned char ulongsize=sizeof(unsigned long);
    9696    char* buffer=new char[ulongsize];
    9797    std::ifstream is("/dev/urandom");
    9898    is.read(buffer,ulongsize);
    9999    is.close();
    100     u_long s=0;
    101     for (u_int i=0; i<ulongsize; i++) {
    102       u_char ch=buffer[i];
     100    unsigned long s=0;
     101    for (unsigned int i=0; i<ulongsize; i++) {
     102      unsigned char ch=buffer[i];
    103103      s+=ch<<((ulongsize-1-i)*8);
    104104    }
     
    146146
    147147
    148   void Discrete::seed(u_long s) const
     148  void Discrete::seed(unsigned long s) const
    149149  {
    150150    rng_->seed(s);
     151  }
     152
     153
     154  unsigned long Discrete::seed_from_devurandom(void)
     155  {
     156    return rng_->seed_from_devurandom();
    151157  }
    152158
     
    172178
    173179
    174   u_long DiscreteGeneral::operator()(void) const
     180  unsigned long DiscreteGeneral::operator()(void) const
    175181  {
    176182    return gsl_ran_discrete(rng_->rng(), gen_);
     
    178184
    179185
    180   DiscreteUniform::DiscreteUniform(u_long n)
     186  DiscreteUniform::DiscreteUniform(unsigned long n)
    181187    : range_(n)
    182188  {
     
    189195
    190196
    191   u_long DiscreteUniform::operator()(void) const
     197  unsigned long DiscreteUniform::operator()(void) const
    192198  {
    193199    return (range_ ?
     
    196202
    197203
    198   u_long DiscreteUniform::operator()(u_long n) const
     204  unsigned long DiscreteUniform::operator()(unsigned long n) const
    199205  {
    200206    // making sure that n is not larger than the range of the
    201207    // underlying RNG
    202208    if (n>rng_->max()) {
    203       std::stringstream ss("DiscreteUniform::operator(u_long): ");
     209      std::stringstream ss("DiscreteUniform::operator(unsigned long): ");
    204210      ss << n << " is too large for RNG " << rng_->name();
    205211      throw utility::GSL_error(ss.str());
     
    214220  }
    215221
    216   u_long Poisson::operator()(void) const
     222  unsigned long Poisson::operator()(void) const
    217223  {
    218224    return gsl_ran_poisson(rng_->rng(), m_);
     
    220226
    221227
    222   u_long Poisson::operator()(const double m) const
     228  unsigned long Poisson::operator()(const double m) const
    223229  {
    224230    return gsl_ran_poisson(rng_->rng(), m);
     
    238244
    239245
    240   void Continuous::seed(u_long s) const
     246  void Continuous::seed(unsigned long s) const
    241247  {
    242248    rng_->seed(s);
  • trunk/yat/random/random.h

    r1004 r1271  
    9898    /// generator can return.
    9999    ///
    100     u_long max(void) const;
     100    unsigned long max(void) const;
    101101
    102102    ///
     
    104104    /// generator can return.
    105105    ///
    106     u_long min(void) const;
     106    unsigned long min(void) const;
    107107
    108108    ///
     
    125125    /// @see seed_from_devurandom
    126126    ///
    127     void seed(u_long s) const;
     127    void seed(unsigned long s) const;
    128128
    129129    ///
     
    132132    /// @return The seed acquired from /dev/urandom.
    133133    ///
    134     u_long seed_from_devurandom(void);
     134    unsigned long seed_from_devurandom(void);
    135135
    136136    /**
     
    221221    /// @see seed_from_devurandom, RNG::seed_from_devurandom, RNG::seed
    222222    ///
    223     void seed(u_long s) const;
     223    void seed(unsigned long s) const;
    224224
    225225    ///
     
    230230    /// @see seed, RNG::seed_from_devurandom, RNG::seed
    231231    ///
    232     u_long seed_from_devurandom(void) { return rng_->seed_from_devurandom(); }
     232    unsigned long seed_from_devurandom(void);
    233233
    234234    ///
    235235    /// @return A random number.
    236236    ///
    237     virtual u_long operator()(void) const = 0;
     237    virtual unsigned long operator()(void) const = 0;
    238238   
    239239  protected:
     
    268268    /// @return A random number.
    269269    ///
    270     u_long operator()(void) const;
     270    unsigned long operator()(void) const;
    271271
    272272  private:
     
    302302       is thrown.
    303303    */
    304     DiscreteUniform(u_long n=0);
     304    DiscreteUniform(unsigned long n=0);
    305305
    306306    /**
     
    311311       created.
    312312
    313        \see DiscreteUniform(const u_long n=0)
     313       \see DiscreteUniform(const unsigned long n=0)
    314314    */
    315     u_long operator()(void) const;
     315    unsigned long operator()(void) const;
    316316
    317317    /**
     
    325325       underlying generator.
    326326    */
    327     u_long operator()(u_long n) const;
    328 
    329   private:
    330     u_long range_;
     327    unsigned long operator()(unsigned long n) const;
     328
     329  private:
     330    unsigned long range_;
    331331  };
    332332
     
    359359    /// @return A Poisson distributed number.
    360360    ///
    361     u_long operator()(void) const;
     361    unsigned long operator()(void) const;
    362362
    363363    ///
     
    367367    /// @note this operator ignores parameters set in Constructor
    368368    ///
    369     u_long operator()(const double m) const;
     369    unsigned long operator()(const double m) const;
    370370
    371371  private:
     
    403403    /// @see seed_from_devurandom, RNG::seed_from_devurandom, RNG::seed
    404404    ///
    405     void seed(u_long s) const;
     405    void seed(unsigned long s) const;
    406406
    407407    ///
     
    412412    /// @see seed, RNG::seed_from_devurandom, RNG::seed
    413413    ///
    414     u_long seed_from_devurandom(void) { return rng_->seed_from_devurandom(); }
     414    unsigned long seed_from_devurandom(void) { return rng_->seed_from_devurandom(); }
    415415
    416416    ///
Note: See TracChangeset for help on using the changeset viewer.