yat  0.21pre
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 argument_type
 argument type is unsigned long int
 
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...
 
unsigned long int min (void) const
 
unsigned long int max (void) const
 
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

◆ result_type

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

type returned by operator()

Since
New in yat 0.10

Constructor & Destructor Documentation

◆ DiscreteUniform()

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

◆ max()

unsigned long int theplu::yat::random::DiscreteUniform::max ( void  ) const

For n>0 the max value is n-1. For n=0 (default) the max value is RNG::max().

Returns
maximal value that class returns
Since
New in yat 0.18

◆ min()

unsigned long int theplu::yat::random::DiscreteUniform::min ( void  ) const

For n>0 the min value is 0. For n=0 (default) the min value is RNG::min(), typically zero but depending on generator in use.

Returns
smallest possible value
Since
New in yat 0.18

◆ operator()() [1/2]

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.

◆ operator()() [2/2]

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.

◆ seed()

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.

◆ seed_from_devurandom()

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 Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14