RandomLib
1.10
|
Sample exactly from a power distribution. More...
#include <RandomLib/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).
This class uses some mutable RandomNumber objects. So a single ExactPower object cannot safely be used by multiple threads. In a multi-processing environment, each thread should use a thread-specific ExactPower object. In addition, these should be invoked with thread-specific random generator objects.
bits | the number of bits in each digit. |
Definition at line 35 of file ExactPower.hpp.
RandomNumber< bits > RandomLib::ExactPower< bits >::operator() | ( | Random & | r, |
unsigned | n | ||
) | const |
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 and n = 2 can be is shown by the 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.
Random | the type of the random generator. |
[in,out] | r | a random generator. |
[in] | n | the power. |
Definition at line 79 of file ExactPower.hpp.