28
28
*/
29
29
30
30
/*
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.
33
33
*
34
34
* 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.
36
37
*
37
38
* Usage example:
38
39
* #include <random>
39
40
* #include "selfsimilar_int_distribution.h"
40
41
* int main()
41
42
* {
42
43
* 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);
44
45
* int i = distribution(generator);
45
46
* }
46
47
*/
53
54
template <typename _IntType = int >
54
55
class selfsimilar_int_distribution
55
56
{
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. " );
57
58
58
59
public:
59
60
/* * The type of the range of the distribution. */
@@ -63,7 +64,7 @@ class selfsimilar_int_distribution
63
64
{
64
65
typedef selfsimilar_int_distribution<_IntType> distribution_type;
65
66
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 )
67
68
: _M_a(__a), _M_b(__b), _M_skew(__skew)
68
69
{
69
70
assert (_M_a <= _M_b && _M_skew > 0.0 && _M_skew < 1.0 );
@@ -148,10 +149,9 @@ class selfsimilar_int_distribution
148
149
result_type operator ()(_UniformRandomNumberGenerator& __urng, const param_type& __p)
149
150
{
150
151
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 ())));
155
155
}
156
156
157
157
/* *
0 commit comments