yat  0.14.5pre
Public Types | Public Member Functions | Protected Attributes | List of all members
theplu::yat::random::DiscreteUniform Class Reference

Discrete uniform distribution. More...

#include <yat/random/random.h>

Inheritance diagram for theplu::yat::random::DiscreteUniform:
theplu::yat::random::Discrete

Public Types

typedef unsigned long int result_type
 

Public Member Functions

 DiscreteUniform (unsigned long n=0)
 Constructor. More...
 
unsigned long operator() (void) const
 Get a random number. More...
 
unsigned long operator() (unsigned long n) const
 Get a random integer in the range $ [0,n-1] $. More...
 
void seed (unsigned long s) const
 Set the seed to s. More...
 
unsigned long seed_from_devurandom (void)
 Set the seed using the /dev/urandom device. More...
 

Protected Attributes

RNGrng_
 GSL random gererator.
 

Detailed Description

Discrete uniform distribution.

Discrete uniform distribution also known as the "equally likely outcomes" distribution. Each outcome, in this case an integer from [0,n-1] , have equal probability to occur.

Distribution function $ p(k) = \frac{1}{n+1} $ for $ 0 \le k < n $
Expectation value: $ \frac{n-1}{2} $
Variance: $ \frac{1}{12}(n-1)(n+1) $

Member Typedef Documentation

typedef unsigned long int theplu::yat::random::Discrete::result_type
inherited

type returned by operator()

Since
New in yat 0.10

Constructor & Destructor Documentation

theplu::yat::random::DiscreteUniform::DiscreteUniform ( unsigned long  n = 0)
explicit

Constructor.

The generator will generate integers within the range $ [0,n-1] $. If n is zero, then the whole range of the underlying RNG will be used $ [min,max] $. Setting n to zero is the preferred way to sample the whole range of the underlying RNG, i.e. not setting
to RNG.max.

Exceptions
Ifn is larger than the maximum number the underlying random number generator can return, then a GSL_error exception is thrown.

Member Function Documentation

unsigned long theplu::yat::random::DiscreteUniform::operator() ( void  ) const
virtual

Get a random number.

The returned integer is either in the range [RNG.min,RNG.max] or [0,n-1] depending on how the random number generator was created.

See Also
DiscreteUniform(const unsigned long n=0)

Implements theplu::yat::random::Discrete.

unsigned long theplu::yat::random::DiscreteUniform::operator() ( unsigned long  n) const

Get a random integer in the range $ [0,n-1] $.

All integers in the range [0,n-1] are equally likely. This function should be avoided for sampling the whole range of the underlying RNG.

Exceptions
GSL_errorif n is larger than the range of the underlying generator.
void theplu::yat::random::Discrete::seed ( unsigned long  s) const
inherited

Set the seed to s.

Set the seed to s in the underlying rng. If s is zero, a default value from the rng's original implementation is used (cf. GSL documentation).

Deprecated:
Provided for backward compatibility with the 0.7 API. Use RNG::instance()->seed(s) instead.
unsigned long theplu::yat::random::Discrete::seed_from_devurandom ( void  )
inherited

Set the seed using the /dev/urandom device.

Returns
The seed acquired from /dev/urandom.
Deprecated:
Provided for backward compatibility with the 0.7 API. Use RNG::instance()->seed_from_devurandom() instead.

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

Generated on Tue Sep 26 2017 02:33:30 for yat by  doxygen 1.8.5