RandomLib  1.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Attributes | List of all members
RandomLib::RandomCanonical< Generator > Class Template Reference

Generate random integers, reals, and booleans. More...

#include <RandomLib/RandomCanonical.hpp>

Inheritance diagram for RandomLib::RandomCanonical< Generator >:

Public Types

enum  { width = Generator::width }
 
typedef Generator::result_type result_type
 
typedef RandomSeed::seed_type seed_type
 

Public Member Functions

template<>
RandomCanonical
< MRandomGenerator32
Global
 
template<>
RandomCanonical
< MRandomGenerator64
Global
 
template<>
RandomCanonical
< SRandomGenerator32
Global
 
template<>
RandomCanonical
< SRandomGenerator64
Global
 
Constructors which set the seed
template<typename IntType >
 RandomCanonical (const std::vector< IntType > &v)
 
template<typename InputIterator >
 RandomCanonical (InputIterator a, InputIterator b)
 
 RandomCanonical (seed_type n)
 
 RandomCanonical ()
 
 RandomCanonical (const std::string &s)
 
Member functions returning integers
result_type operator() () throw ()
 
result_type operator() (result_type n) throw ()
 
template<typename IntType , int bits>
IntType Integer () throw ()
 
template<int bits>
result_type Integer () throw ()
 
template<typename IntType >
IntType Integer () throw ()
 
result_type Integer () throw ()
 
template<typename IntType >
IntType Integer (IntType n) throw ()
 
template<typename IntType >
IntType IntegerC (IntType n) throw ()
 
template<typename IntType >
IntType IntegerC (IntType m, IntType n) throw ()
 
Member functions returning real fixed-point numbers
template<typename RealType , int prec>
RealType Fixed () throw ()
 
template<typename RealType >
RealType Fixed () throw ()
 
double Fixed () throw ()
 
template<typename RealType >
RealType Real () throw ()
 
double Real () throw ()
 
template<typename RealType , int prec>
RealType FixedU () throw ()
 
template<typename RealType >
RealType FixedU () throw ()
 
double FixedU () throw ()
 
template<typename RealType , int prec>
RealType FixedN () throw ()
 
template<typename RealType >
RealType FixedN () throw ()
 
double FixedN () throw ()
 
template<typename RealType , int prec>
RealType FixedW () throw ()
 
template<typename RealType >
RealType FixedW () throw ()
 
double FixedW () throw ()
 
template<typename RealType , int prec>
RealType FixedS () throw ()
 
template<typename RealType >
RealType FixedS () throw ()
 
double FixedS () throw ()
 
template<typename RealType , int prec>
RealType FixedO () throw ()
 
template<typename RealType >
RealType FixedO () throw ()
 
double FixedO () throw ()
 
template<typename RealType , int prec>
RealType FixedC () throw ()
 
template<typename RealType >
RealType FixedC () throw ()
 
double FixedC () throw ()
 
Member functions returning real floating-point numbers
template<typename RealType , int prec, int erange>
RealType Float () throw ()
 
template<typename RealType >
RealType Float () throw ()
 
double Float () throw ()
 
template<typename RealType , int prec, int erange>
RealType FloatU () throw ()
 
template<typename RealType >
RealType FloatU () throw ()
 
double FloatU () throw ()
 
template<typename RealType , int prec, int erange>
RealType FloatN () throw ()
 
template<typename RealType >
RealType FloatN () throw ()
 
double FloatN () throw ()
 
template<typename RealType , int prec, int erange>
RealType FloatW () throw ()
 
template<typename RealType >
RealType FloatW () throw ()
 
double FloatW () throw ()
 
Member functions returning booleans
bool Boolean () throw ()
 
template<typename NumericType >
bool Prob (NumericType p) throw ()
 
template<typename NumericType >
bool Prob (NumericType m, NumericType n) throw ()
 
Functions returning bitsets

These return random bits in a std::bitset.

template<int nbits>
std::bitset< nbits > Bits () throw ()
 

Static Public Attributes

static RANDOMLIB_EXPORT
RandomCanonical 
Global
 

Detailed Description

template<class Generator>
class RandomLib::RandomCanonical< Generator >

Generate random integers, reals, and booleans.

Use the random bits from Generator to produce random integers of various sizes, random reals with various precisions, a random probability, etc. RandomCanonical assumes that Generator produces random results as 32-bit quantities (of type uint32_t) via Generator::Ran32(), 64-bit quantities (of type uint64_t) via Generator::Ran64(), and in "natural" units of Generator::width bits (of type Generator::result_type) via Generator::Ran().

For the most part this class uses Ran() when needing width or fewer bits, otherwise it uses Ran64(). However, when width = 64, the resulting code is RandomCanonical::Unsigned(n) is inefficient because of the 64-bit arithmetic. For this reason RandomCanonical::Unsigned(n) uses Ran32() if less than 32 bits are required (even though this results in more numbers being produced by the Generator).

This class has been tested with the 32-bit and 64-bit versions of MT19937 and SFMT19937. Other random number generators could be used provided that they provide a whole number of random bits so that Ran() is uniformly distributed in [0,2w). Probably some modifications would be needed if w is not 32 or 64.

Template Parameters
Generatorthe type of the underlying generator.

Definition at line 55 of file RandomCanonical.hpp.

Member Typedef Documentation

template<class Generator>
typedef Generator::result_type RandomLib::RandomCanonical< Generator >::result_type

The type of operator()().

Definition at line 60 of file RandomCanonical.hpp.

template<class Generator>
typedef RandomSeed::seed_type RandomLib::RandomCanonical< Generator >::seed_type

The type of elements of Seed().

Definition at line 64 of file RandomCanonical.hpp.

Member Enumeration Documentation

template<class Generator>
anonymous enum
Enumerator
width 

The number of random bits in result_type.

Definition at line 65 of file RandomCanonical.hpp.

Constructor & Destructor Documentation

template<class Generator>
template<typename IntType >
RandomLib::RandomCanonical< Generator >::RandomCanonical ( const std::vector< IntType > &  v)
inlineexplicit

Initialize from a vector.

Template Parameters
IntTypethe integral type of the elements of the vector.
Parameters
[in]vthe vector of elements.

Definition at line 83 of file RandomCanonical.hpp.

template<class Generator>
template<typename InputIterator >
RandomLib::RandomCanonical< Generator >::RandomCanonical ( InputIterator  a,
InputIterator  b 
)
inline

Initialize from a pair of iterator setting seed to [a, b)

Template Parameters
InputIteratorthe type of the iterator.
Parameters
[in]athe beginning iterator.
[in]bthe ending iterator.

Definition at line 92 of file RandomCanonical.hpp.

template<class Generator >
RandomLib::RandomCanonical< Generator >::RandomCanonical ( seed_type  n)
explicit
template<class Generator>
RandomLib::RandomCanonical< Generator >::RandomCanonical ( )
inline

Initialize with seed []. This can be followed by a call to Reseed() to select a unique seed.

Definition at line 103 of file RandomCanonical.hpp.

template<class Generator>
RandomLib::RandomCanonical< Generator >::RandomCanonical ( const std::string &  s)
inlineexplicit

Initialize from a string. See RandomCanonical::StringToVector

Parameters
[in]sthe string to be decoded into a seed.

Definition at line 109 of file RandomCanonical.hpp.

Member Function Documentation

template<class Generator>
result_type RandomLib::RandomCanonical< Generator >::operator() ( )
throw (
)
inline

Return a raw result in [0, 2w) from the underlying Generator.

Returns
a w-bit random number.

Definition at line 122 of file RandomCanonical.hpp.

template<class Generator>
result_type RandomLib::RandomCanonical< Generator >::operator() ( result_type  n)
throw (
)
inline

A random integer in [0, n). This allows a RandomCanonical object to be passed to those standard template library routines that require random numbers. E.g.,

int a[] = {0, 1, 2, 3, 4};
std::random_shuffle(a, a+5, r);
Parameters
[in]nthe upper end of the interval. The upper end of the interval is open, so n is never returned.
Returns
the random integer in [0, n).

Definition at line 138 of file RandomCanonical.hpp.

template<class Generator>
template<typename IntType , int bits>
IntType RandomLib::RandomCanonical< Generator >::Integer ( )
throw (
)
inline

A random integer of type IntType in [0, 2b).

Template Parameters
IntTypethe integer type of the returned random numbers.
bitshow many random bits to return.
Returns
the random result.

Definition at line 150 of file RandomCanonical.hpp.

References RandomLib::RandomType< bits, UIntType >::mask, STATIC_ASSERT, and RandomLib::RandomCanonical< Generator >::width.

template<class Generator>
template<int bits>
result_type RandomLib::RandomCanonical< Generator >::Integer ( )
throw (
)
inline

A random integer in [0, 2b).

Template Parameters
bitshow many random bits to return.
Returns
the random result.

Definition at line 173 of file RandomCanonical.hpp.

template<class Generator >
template<typename IntType >
IntType RandomLib::RandomCanonical< Generator >::Integer ( )
throw (
)
inline

A random integer of type IntType in [std::numeric_limits<IntType>::min(), std::numeric_limits::max()].

Template Parameters
IntTypethe integer type of the returned random numbers.
Returns
the random result.

Definition at line 863 of file RandomCanonical.hpp.

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

template<class Generator>
result_type RandomLib::RandomCanonical< Generator >::Integer ( )
throw (
)
inline

A random result_type in [0, std::numeric_limits<result_type>::max()].

Returns
the random result.

Definition at line 189 of file RandomCanonical.hpp.

template<class Generator >
template<typename IntType >
IntType RandomLib::RandomCanonical< Generator >::Integer ( IntType  n)
throw (
)
inline

A random integer of type IntType in [0, n). Excludes n. If n == 0, treat as std::numeric_limits::max() + 1. If n < 0, return 0. Compare RandomCanonical::Integer<int>(0) which returns a result in [0,231) with RandomCanonical::Integer<int>() which returns a result in [−231,231).

Template Parameters
IntTypethe integer type of the returned random numbers.
Parameters
[in]nthe upper end of the semi-open interval.
Returns
the random result in [0, n).

Definition at line 921 of file RandomCanonical.hpp.

References RandomLib::RandomType< bits, UIntType >::mask, and STATIC_ASSERT.

template<class Generator >
template<typename IntType >
IntType RandomLib::RandomCanonical< Generator >::IntegerC ( IntType  n)
throw (
)
inline

A random integer of type IntType in Closed interval [0, n]. Includes n. If n < 0, return 0.

Template Parameters
IntTypethe integer type of the returned random numbers.
Parameters
[in]nthe upper end of the closed interval.
Returns
the random result in [0, n].

Definition at line 942 of file RandomCanonical.hpp.

References RandomLib::RandomType< bits, UIntType >::mask, and STATIC_ASSERT.

Referenced by main().

template<class Generator >
template<typename IntType >
IntType RandomLib::RandomCanonical< Generator >::IntegerC ( IntType  m,
IntType  n 
)
throw (
)
inline

A random integer of type IntType in Closed interval [m, n]. Includes both endpoints. If n < m, return m.

Template Parameters
IntTypethe integer type of the returned random numbers.
Parameters
[in]mthe lower end of the closed interval.
[in]nthe upper end of the closed interval.
Returns
the random result in [m, n].

Definition at line 958 of file RandomCanonical.hpp.

References STATIC_ASSERT.

template<class Generator>
template<typename RealType , int prec>
RealType RandomLib::RandomCanonical< Generator >::Fixed ( )
throw (
)
inline

In the description of the functions FixedX returning fixed-point numbers, u is a random real number uniformly distributed in (0, 1), p is the precision, and h = 1/2p. Each of the functions come in three variants, e.g.,

See the summary for a comparison of the functions.

Return i h with i in [0,2p) by rounding u down to the previous fixed real. Result is in default interval [0,1).

Template Parameters
RealTypethe real type of the returned random numbers.
precthe precision of the returned random numbers.
Returns
the random result.

Definition at line 253 of file RandomCanonical.hpp.

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

Referenced by main(), and RandomLib::RandomCanonical< Generator >::Real().

template<class Generator>
template<typename RealType >
RealType RandomLib::RandomCanonical< Generator >::Fixed ( )
throw (
)
inline

See documentation for RandomCanonical::Fixed<RealType,prec>().

Template Parameters
RealTypethe real type of the returned random numbers.
Returns
the random result with the full precision of RealType.

Definition at line 281 of file RandomCanonical.hpp.

template<class Generator>
double RandomLib::RandomCanonical< Generator >::Fixed ( )
throw (
)
inline

See documentation for RandomCanonical::Fixed<RealType,prec>().

Returns
the random double.

Definition at line 288 of file RandomCanonical.hpp.

template<class Generator>
template<typename RealType >
RealType RandomLib::RandomCanonical< Generator >::Real ( )
throw (
)
inline

An alias for RandomCanonical::Fixed<RealType>(). Returns a random number of type RealType in [0,1).

Template Parameters
RealTypethe real type of the returned random numbers.
Returns
the random result with the full precision of RealType.

Definition at line 297 of file RandomCanonical.hpp.

template<class Generator>
double RandomLib::RandomCanonical< Generator >::Real ( )
throw (
)
inline

An alias for RandomCanonical::Fixed(). Returns a random double in [0,1).

Returns
the random double.

Definition at line 305 of file RandomCanonical.hpp.

References RandomLib::RandomCanonical< Generator >::Fixed().

template<class Generator>
template<typename RealType , int prec>
RealType RandomLib::RandomCanonical< Generator >::FixedU ( )
throw (
)
inline

Return i h with i in (0,2p] by rounding u up to the next fixed real. Result is in upper interval (0,1].

Template Parameters
RealTypethe real type of the returned random numbers.
precthe precision of the returned random numbers.
Returns
the random result.

Definition at line 316 of file RandomCanonical.hpp.

template<class Generator>
template<typename RealType >
RealType RandomLib::RandomCanonical< Generator >::FixedU ( )
throw (
)
inline

See documentation for RandomCanonical::FixedU<RealType,prec>().

Template Parameters
RealTypethe real type of the returned random numbers.
Returns
the random result with the full precision of RealType.

Definition at line 324 of file RandomCanonical.hpp.

template<class Generator>
double RandomLib::RandomCanonical< Generator >::FixedU ( )
throw (
)
inline

See documentation for RandomCanonical::FixedU<RealType,prec>().

Returns
the random double.

Definition at line 331 of file RandomCanonical.hpp.

template<class Generator>
template<typename RealType , int prec>
RealType RandomLib::RandomCanonical< Generator >::FixedN ( )
throw (
)
inline

Return i h with i in [0,2p] by rounding u to the nearest fixed real. Result is in nearest interval [0,1]. The probability of returning interior values is h while the probability of returning the endpoints is h/2.

Template Parameters
RealTypethe real type of the returned random numbers.
precthe precision of the returned random numbers.
Returns
the random result.

Definition at line 343 of file RandomCanonical.hpp.

References RandomLib::RandomCanonical< Generator >::Boolean().

template<class Generator>
template<typename RealType >
RealType RandomLib::RandomCanonical< Generator >::FixedN ( )
throw (
)
inline

See documentation for RandomCanonical::FixedN<RealType,prec>().

Template Parameters
RealTypethe real type of the returned random numbers.
Returns
the random result with the full precision of RealType.

Definition at line 353 of file RandomCanonical.hpp.

template<class Generator>
double RandomLib::RandomCanonical< Generator >::FixedN ( )
throw (
)
inline

See documentation for RandomCanonical::FixedN<RealType,prec>().

Returns
the random double.

Definition at line 360 of file RandomCanonical.hpp.

template<class Generator>
template<typename RealType , int prec>
RealType RandomLib::RandomCanonical< Generator >::FixedW ( )
throw (
)
inline

Return i h with i in [−2p, 2p] by rounding 2u − 1 to the nearest fixed real. Result is in wide interval [−1,1]. The probability of returning interior values is h/2 while the probability of returning the endpoints is h/4.

Template Parameters
RealTypethe real type of the returned random numbers.
precthe precision of the returned random numbers.
Returns
the random result.

Definition at line 373 of file RandomCanonical.hpp.

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

template<class Generator>
template<typename RealType >
RealType RandomLib::RandomCanonical< Generator >::FixedW ( )
throw (
)
inline

See documentation for RandomCanonical::FixedW<RealType,prec>().

Template Parameters
RealTypethe real type of the returned random numbers.
Returns
the random result with the full precision of RealType.

Definition at line 398 of file RandomCanonical.hpp.

template<class Generator>
double RandomLib::RandomCanonical< Generator >::FixedW ( )
throw (
)
inline

See documentation for RandomCanonical::FixedW<RealType,prec>().

Returns
the random double.

Definition at line 405 of file RandomCanonical.hpp.

template<class Generator>
template<typename RealType , int prec>
RealType RandomLib::RandomCanonical< Generator >::FixedS ( )
throw (
)
inline

Return (i+1/2)h with i in [2p−1, 2p−1) by rounding u − 1/2 to nearest offset fixed real. Result is in symmetric interval (−1/2,1/2).

Template Parameters
RealTypethe real type of the returned random numbers.
precthe precision of the returned random numbers.
Returns
the random result.

Definition at line 417 of file RandomCanonical.hpp.

Referenced by main().

template<class Generator>
template<typename RealType >
RealType RandomLib::RandomCanonical< Generator >::FixedS ( )
throw (
)
inline

See documentation for RandomCanonical::FixedS<RealType,prec>().

Template Parameters
RealTypethe real type of the returned random numbers.
Returns
the random result with the full precision of RealType.

Definition at line 426 of file RandomCanonical.hpp.

template<class Generator>
double RandomLib::RandomCanonical< Generator >::FixedS ( )
throw (
)
inline

See documentation for RandomCanonical::FixedS<RealType,prec>().

Returns
the random double.

Definition at line 433 of file RandomCanonical.hpp.

template<class Generator>
template<typename RealType , int prec>
RealType RandomLib::RandomCanonical< Generator >::FixedO ( )
throw (
)
inline

Return i h with i in (0,2p) by rounding (1 − h)u up to next fixed real. Result is in open interval (0,1).

Template Parameters
RealTypethe real type of the returned random numbers.
precthe precision of the returned random numbers.
Returns
the random result.

Definition at line 444 of file RandomCanonical.hpp.

References STATIC_ASSERT.

template<class Generator>
template<typename RealType >
RealType RandomLib::RandomCanonical< Generator >::FixedO ( )
throw (
)
inline

See documentation for RandomCanonical::FixedO<RealType,prec>().

Template Parameters
RealTypethe real type of the returned random numbers.
Returns
the random result with the full precision of RealType.

Definition at line 464 of file RandomCanonical.hpp.

template<class Generator>
double RandomLib::RandomCanonical< Generator >::FixedO ( )
throw (
)
inline

See documentation for RandomCanonical::FixedO<RealType,prec>().

Returns
the random double.

Definition at line 471 of file RandomCanonical.hpp.

template<class Generator>
template<typename RealType , int prec>
RealType RandomLib::RandomCanonical< Generator >::FixedC ( )
throw (
)
inline

Return i h with i in [0,2p] by rounding (1 + h)u down to previous fixed real. Result is in closed interval [0,1].

Template Parameters
RealTypethe real type of the returned random numbers.
precthe precision of the returned random numbers.
Returns
the random result.

Definition at line 482 of file RandomCanonical.hpp.

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

template<class Generator>
template<typename RealType >
RealType RandomLib::RandomCanonical< Generator >::FixedC ( )
throw (
)
inline

See documentation for RandomCanonical::FixedC<RealType,prec>().

Template Parameters
RealTypethe real type of the returned random numbers.
Returns
the random result with the full precision of RealType.

Definition at line 545 of file RandomCanonical.hpp.

template<class Generator>
double RandomLib::RandomCanonical< Generator >::FixedC ( )
throw (
)
inline

See documentation for RandomCanonical::FixedC<RealType,prec>().

Returns
the random double.

Definition at line 552 of file RandomCanonical.hpp.

template<class Generator>
template<typename RealType , int prec, int erange>
RealType RandomLib::RandomCanonical< Generator >::Float ( )
throw (
)
inline

In the description of the functions FloatX returning floating-point numbers, u is a random real number uniformly distributed in (0, 1), p is the precision, and e is the exponent range. Each of the functions come in three variants, e.g.,

See the summary for a comparison of the functions.

Return result is in default interval [0,1) by rounding u down to the previous floating real.

Template Parameters
RealTypethe real type of the returned random numbers.
precthe precision of the returned random numbers.
erangethe exponent range of the returned random numbers.
Returns
the random result.

Definition at line 586 of file RandomCanonical.hpp.

template<class Generator>
template<typename RealType >
RealType RandomLib::RandomCanonical< Generator >::Float ( )
throw (
)
inline

See documentation for RandomCanonical::Float<RealType,prec,erange>().

Template Parameters
RealTypethe real type of the returned random numbers.
Returns
the random result with the full precision of RealType.

Definition at line 594 of file RandomCanonical.hpp.

template<class Generator>
double RandomLib::RandomCanonical< Generator >::Float ( )
throw (
)
inline

See documentation for RandomCanonical::Float<RealType,prec,erange>().

Returns
the random double.

Definition at line 603 of file RandomCanonical.hpp.

template<class Generator>
template<typename RealType , int prec, int erange>
RealType RandomLib::RandomCanonical< Generator >::FloatU ( )
throw (
)
inline

Return result is in upper interval (0,1] by round u up to the next floating real.

Template Parameters
RealTypethe real type of the returned random numbers.
precthe precision of the returned random numbers.
erangethe exponent range of the returned random numbers.
Returns
the random result.

Definition at line 614 of file RandomCanonical.hpp.

template<class Generator>
template<typename RealType >
RealType RandomLib::RandomCanonical< Generator >::FloatU ( )
throw (
)
inline

See documentation for RandomCanonical::FloatU<RealType,prec,erange>().

Template Parameters
RealTypethe real type of the returned random numbers.
Returns
the random result with the full precision of RealType.

Definition at line 622 of file RandomCanonical.hpp.

template<class Generator>
double RandomLib::RandomCanonical< Generator >::FloatU ( )
throw (
)
inline

See documentation for RandomCanonical::FloatU<RealType,prec,erange>().

Returns
the random double.

Definition at line 631 of file RandomCanonical.hpp.

template<class Generator>
template<typename RealType , int prec, int erange>
RealType RandomLib::RandomCanonical< Generator >::FloatN ( )
throw (
)
inline

Return result is in nearest interval [0,1] by rounding u to the nearest floating real.

Template Parameters
RealTypethe real type of the returned random numbers.
precthe precision of the returned random numbers.
erangethe exponent range of the returned random numbers.
Returns
the random result.

Definition at line 642 of file RandomCanonical.hpp.

References RandomLib::RandomCanonical< Generator >::width.

template<class Generator>
template<typename RealType >
RealType RandomLib::RandomCanonical< Generator >::FloatN ( )
throw (
)
inline

See documentation for RandomCanonical::FloatN<RealType,prec,erange>().

Template Parameters
RealTypethe real type of the returned random numbers.
Returns
the random result with the full precision of RealType.

Definition at line 661 of file RandomCanonical.hpp.

template<class Generator>
double RandomLib::RandomCanonical< Generator >::FloatN ( )
throw (
)
inline

See documentation for RandomCanonical::FloatN<RealType,prec,erange>().

Returns
the random double.

Definition at line 670 of file RandomCanonical.hpp.

template<class Generator>
template<typename RealType , int prec, int erange>
RealType RandomLib::RandomCanonical< Generator >::FloatW ( )
throw (
)
inline

Return result is in wide interval [−1,1], by rounding 2u − 1 to the nearest floating real.

Template Parameters
RealTypethe real type of the returned random numbers.
precthe precision of the returned random numbers.
erangethe exponent range of the returned random numbers.
Returns
the random result.

Definition at line 682 of file RandomCanonical.hpp.

References RandomLib::RandomCanonical< Generator >::width.

template<class Generator>
template<typename RealType >
RealType RandomLib::RandomCanonical< Generator >::FloatW ( )
throw (
)
inline

See documentation for RandomCanonical::FloatW<RealType,prec,erange>().

Template Parameters
RealTypethe real type of the returned random numbers.
Returns
the random result with the full precision of RealType.

Definition at line 698 of file RandomCanonical.hpp.

template<class Generator>
double RandomLib::RandomCanonical< Generator >::FloatW ( )
throw (
)
inline

See documentation for RandomCanonical::FloatW<RealType,prec,erange>().

Returns
the random double.

Definition at line 707 of file RandomCanonical.hpp.

template<class Generator>
bool RandomLib::RandomCanonical< Generator >::Boolean ( )
throw (
)
inline
template<class Generator>
template<typename NumericType >
bool RandomLib::RandomCanonical< Generator >::Prob ( NumericType  p)
throw (
)

The Bernoulli distribution, true with probability p. False if p ≤ 0; true if p ≥ 1. Equivalent to RandomCanonical::Float() < p, but typically faster.

Template Parameters
NumericTypethe type (integer or real) of the argument.
Parameters
[in]pthe probability.
Returns
true with probability p.

Referenced by main().

template<class Generator>
template<typename NumericType >
bool RandomLib::RandomCanonical< Generator >::Prob ( NumericType  m,
NumericType  n 
)
throw (
)

True with probability m/n. False if m ≤ 0 or n < 0; true if mn. With real types, Prob(x, y) is exact but slower than Prob(x/y).

Template Parameters
NumericTypethe type (integer or real) of the argument.
Parameters
[in]mthe numerator of the probability.
[in]nthe denominator of the probability.
Returns
true with probability m/n.
template<class Generator >
template<int nbits>
std::bitset< nbits > RandomLib::RandomCanonical< Generator >::Bits ( )
throw (
)
inline

Return nbits random bits

Template Parameters
nbitsthe number of bits in the bitset.
Returns
the random bitset.

Definition at line 1205 of file RandomCanonical.hpp.

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

Referenced by main().

Definition at line 1397 of file Random.cpp.

Definition at line 1399 of file Random.cpp.

Definition at line 1401 of file Random.cpp.

Definition at line 1403 of file Random.cpp.

Member Data Documentation

template<class Generator>
RANDOMLIB_EXPORT RandomCanonical RandomLib::RandomCanonical< Generator >::Global
static

A "global" random number generator (not thread-safe!), initialized with a fixed seed [].

Definition at line 768 of file RandomCanonical.hpp.


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