Skip to content

Commit 375545a

Browse files
committed
Adding comments and fixing formatting.
1 parent 39a9fff commit 375545a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

selfsimilar_int_distribution.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,20 @@
2828
*/
2929

3030
/*
31-
* The selfsimilar_int_distribution class is intended to be compatible with other
32-
* distributions defined in #include<random> by the C++11 standard.
31+
* The selfsimilar_int_distribution class is intended to be compatible with
32+
* other distributions introduced in #include <random> by the C++11 standard.
3333
*
3434
* The distribution of probability is such that the first (N*skew) elements are
35-
* generated (1-skew) of the times.
35+
* generated (1-skew) of the times. This distribution also has the property
36+
* that the skew is the same within any region of the key space.
3637
*
3738
* Usage example:
3839
* #include <random>
3940
* #include "selfsimilar_int_distribution.h"
4041
* int main()
4142
* {
4243
* std::default_random_engine generator;
43-
* std::selfsimilar_int_distribution<int> distribution(1,10,0.2);
44+
* std::selfsimilar_int_distribution<int> distribution(1, 10, 0.2);
4445
* int i = distribution(generator);
4546
* }
4647
*/
@@ -53,7 +54,7 @@
5354
template<typename _IntType = int>
5455
class selfsimilar_int_distribution
5556
{
56-
static_assert(std::is_integral<_IntType>::value, "template argument not an integral type");
57+
static_assert(std::is_integral<_IntType>::value, "Template argument not an integral type.");
5758

5859
public:
5960
/** The type of the range of the distribution. */
@@ -63,7 +64,7 @@ class selfsimilar_int_distribution
6364
{
6465
typedef selfsimilar_int_distribution<_IntType> distribution_type;
6566

66-
explicit param_type(_IntType __a = 0, _IntType __b = std::numeric_limits<_IntType>::max(), double __skew = 0.99)
67+
explicit param_type(_IntType __a = 0, _IntType __b = std::numeric_limits<_IntType>::max(), double __skew = 0.2)
6768
: _M_a(__a), _M_b(__b), _M_skew(__skew)
6869
{
6970
assert(_M_a <= _M_b && _M_skew > 0.0 && _M_skew < 1.0);
@@ -148,10 +149,9 @@ class selfsimilar_int_distribution
148149
result_type operator()(_UniformRandomNumberGenerator& __urng, const param_type& __p)
149150
{
150151
double u = std::generate_canonical<double, std::numeric_limits<double>::digits, _UniformRandomNumberGenerator>(__urng);
151-
return __p.a() + (
152-
(__p.b() - __p.a() + 1) *
153-
std::pow(u, std::log(__p.skew()) / std::log(1.0-__p.skew()))
154-
);
152+
unsigned long N = __p.b() - __p.a() + 1;
153+
return __p.a() + (N *
154+
std::pow(u, std::log(__p.skew()) / std::log(1.0-__p.skew())));
155155
}
156156

157157
/**

0 commit comments

Comments
 (0)