RandomLib  1.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Public Member Functions | List of all members
RandomLib::LeadingZeros Class Reference

Count of leading zeros. More...

#include <RandomLib/LeadingZeros.hpp>

Public Member Functions

template<class Random >
unsigned operator() (Random &r) const throw ()
 

Detailed Description

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

RandomLib::Random r; // A RandomGenerator works here too
std::cout << "Seed set to " << r.SeedString() << "\n";
LeadingZeros zeros;
std::cout << "Count of leading zeros:";
for (size_t i = 0; i < 20; ++i)
std::cout << " " << zeros(r);
std::cout << "\n";

Definition at line 34 of file LeadingZeros.hpp.

Member Function Documentation

template<class Random >
unsigned RandomLib::LeadingZeros::operator() ( Random r) const
throw (
)

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).

Template Parameters
Randomthe type of the random generator.
Parameters
[in,out]ra random generator.
Returns
the random sample.

Definition at line 50 of file LeadingZeros.hpp.

References STATIC_ASSERT, and RandomLib::RandomCanonical< Generator >::width.


The documentation for this class was generated from the following file: