Count of leading zeros. More...
#include <RandomLib-2010-01/LeadingZeros.hpp>
Public Member Functions | |
template<class Random > | |
unsigned | operator() (Random &r) const throw () |
Count of leading zeros.
Count of leading zero bits after the binary point in a real number uniformly distributed in (0,1). (This is equivalent to the geometric distribution with probability 1/2.) For example
#include "RandomLib/LeadingZeros.hpp" RandomLib::Random r; // A RandomGenerator works here too std::cout << "Seed set to " << r.SeedString() << std::endl; LeadingZeros zeros; std::cout << "Count of leading zeros:"; for (size_t i = 0; i < 20; ++i) std::cout << " " << zeros(r); std::cout << std::endl;
unsigned RandomLib::LeadingZeros::operator() | ( | Random & | r | ) | const throw () [inline] |
Return the number of zero bits after the binary point in a real number uniformly distributed in (0,1). Thus k is returned with probability 1/2k+1. Because MT19937 is not a perfect random number generator, this always returns a result in [0, 19937).
Definition at line 45 of file LeadingZeros.hpp.