Sample exactly from a power distribution. More...
#include <RandomLib-2010-01/ExactPower.hpp>
Public Member Functions | |
template<class Random > | |
RandomNumber< bits > | operator() (Random &r, unsigned n) const |
Sample exactly from a power distribution.
Sample exactly from power distribution (n + 1) xn for x in (0,1) and integer n >= 0 using infinite precision. The template parameter bits specifies the number of bits in the base used for RandomNumber (i.e., base = 2bits).
RandomNumber< bits > RandomLib::ExactPower::operator() | ( | Random & | r, |
unsigned | n | ||
) | const [inline] |
Return the random deviate with a power distribution, (n + 1) xn for x in (0,1) and integer n >= 0. Returned result is a RandomNumber with base 2bits. For bits = 1, the number of random bits in the result and consumed are as follows:
n random bits result consumed 0 0 0 1 2 4 2 2.33 6.67 3 2.67 9.24 4 2.96 11.71 5 3.20 14.11 6 3.41 16.45 7 3.59 18.75 8 3.75 21.01 9 3.89 23.25 10 4.02 25.47
The relative frequency of the results with bits = 1 can be shown via a histogram
The base of each rectangle gives the range represented by the corresponding binary number and the area is proportional to its frequency. A PDF version of this figure here. This allows the figure to be magnified to show the rectangles for all binary numbers up to 9 bits.
Definition at line 62 of file ExactPower.hpp.
References RandomLib::RandomNumber::Init(), and RandomLib::RandomNumber::LessThan().