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

List of all members.

Public Member Functions

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

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


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:
If n 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_error if 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).

See also:
seed_from_devurandom, RNG::seed_from_devurandom, RNG::seed

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.
See also:
seed, RNG::seed_from_devurandom, RNG::seed


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

Generated on Tue Jan 18 02:21:18 2011 for yat by  doxygen 1.5.5