Changeset 5913 for lang/cplusplus

Show
Ignore:
Timestamp:
01/31/08 01:45:27 (5 years ago)
Author:
mrkn
Message:

lang/cplusplus/boost-supplement/trunk/boost_supplement/random/zipf_distribution.hpp: Correct the return type of make_dist function, and modify buffer initialization and a for-loop condition.
lang/cplusplus/boost-supplement/trunk/boost_supplement/random/discrete_distribution.hpp: Includes <boost/assert.hpp>. Modifies operator() to correct its wrong algorithm.

Location:
lang/cplusplus/boost-supplement/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/cplusplus/boost-supplement/trunk/ChangeLog

    r5908 r5913  
    112008-01-31  Kenta Murata  <muraken@gmail.com> 
     2 
     3        * boost_supplement/random/zipf_distribution.hpp: Correct the 
     4        return type of make_dist function, and modify buffer 
     5        initialization and a for-loop condition. 
     6 
     7        * boost_supplement/random/discrete_distribution.hpp: Includes 
     8        <boost/assert.hpp>.  Modifies operator() to correct its wrong 
     9        algorithm. 
    210 
    311        * boost_supplement/random/zipf_distribution.hpp 
  • lang/cplusplus/boost-supplement/trunk/boost_supplement/random/discrete_distribution.hpp

    r5906 r5913  
    1313#define BOOST_SUPPLEMENT_DISCRETE_DISTRIBUTION_HPP 1 
    1414 
     15#include <boost/assert.hpp> 
    1516#include <boost/random/uniform_real.hpp> 
    1617#include <boost/concept_check.hpp> 
     
    166167    { 
    167168      boost::uniform_real<input_type> ud; 
    168       input_type u = ud(eng); 
     169      input_type u = ud(eng)*num(); 
    169170      result_type x = result_type(u); 
    170171      u -= x; 
    171       if (probabilities_[x] < u) return x; 
     172      if (u < probabilities_[x]) return x; 
    172173      return aliases_[x]; 
    173174    } 
  • lang/cplusplus/boost-supplement/trunk/boost_supplement/random/zipf_distribution.hpp

    r5908 r5913  
    4747  dist_type dist_; 
    4848 
    49   void make_dist(result_type num, input_type shift, input_type exp) 
     49  dist_type make_dist(result_type num, input_type shift, input_type exp) 
    5050    { 
    51       std::vector<input_type> buffer(num); 
    52       for (result_type k = 1; k <= num; ++k) 
     51      std::vector<input_type> buffer(num + 1, input_type(0)); 
     52      for (result_type k = 1; k < num; ++k) 
    5353        buffer[k] = std::pow(k + shift, -exp); 
    5454      return dist_type(buffer.begin(), buffer.end());