[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

RandomNumberGenerator< Engine > Class Template Reference

`#include <vigra/random.hxx>`

Inherits RandomState< EngineTag >.

## Public Member Functions

double | normal () const
double | normal (double mean, double stddev) const
UInt32 | operator() () const
| RandomNumberGenerator ()
template<class Iterator >
| RandomNumberGenerator (Iterator init, UInt32 length)
| RandomNumberGenerator (RandomSeedTag)
| RandomNumberGenerator (UInt32 theSeed, bool ignoreSeed=false)
template<class Iterator >
void | seed (Iterator init, UInt32 length)
void | seed (RandomSeedTag)
void | seed (UInt32 theSeed, bool ignoreSeed=false)
double | uniform () const
double | uniform (double lower, double upper) const
double | uniform53 () const
UInt32 | uniformInt () const
UInt32 | uniformInt (UInt32 beyond) const

## Static Public Member Functions

static RandomNumberGenerator & | global ()

## Detailed Description

template<class Engine = detail::RandomState<detail::MT19937>>
class vigra::RandomNumberGenerator< Engine >

Generic random number generator.

The actual generator is passed in the template argument `Engine`. Two generators are currently available:

- `RandomMT19937`: The state-of-the-art Mersenne Twister with a state length of 219937 and very high statistical quality.
- `RandomTT800`: (default) The Tempered Twister, a simpler predecessor of the Mersenne Twister with period length 2800.

Both generators have been designed by Makoto Matsumoto.

Traits defined:

    FunctorTraits<RandomNumberGenerator<Engine> >::isInitializer

is true (`VigraTrueType`).

## Constructor & Destructor Documentation

## ◆ RandomNumberGenerator() [1/4]

template<class Engine = detail::RandomState<detail::MT19937>>

RandomNumberGenerator | ( |  | ) |

Create a new random generator object with standard seed.

Due to standard seeding, the random numbers generated will always be the same. This is useful for debugging.

## ◆ RandomNumberGenerator() [2/4]

template<class Engine = detail::RandomState<detail::MT19937>>

RandomNumberGenerator | ( | RandomSeedTag |  | ) |

Create a new random generator object with a random seed.

The seed is obtained from the machines current `clock()` and `time()` values.

Usage:

RandomNumberGenerator<> rnd = RandomNumberGenerator<>(RandomSeed);
vigra::RGBValue
Class for a single RGB value.
Definition rgbvalue.hxx:128

## ◆ RandomNumberGenerator() [3/4]

template<class Engine = detail::RandomState<detail::MT19937>>

RandomNumberGenerator | ( | UInt32 | theSeed,
|  | bool | ignoreSeed = `false`
| ) |  |

Create a new random generator object from the given seed.

The same seed will always produce identical random sequences. If ignoreSeed is `true`, the given seed is ignored, and the generator is seeded randomly (as if it was constructed with `RandomNumberGenerator<>(RandomSeed)`). This allows you to switch between random and deterministic seeding at run-time.

## ◆ RandomNumberGenerator() [4/4]

template<class Engine = detail::RandomState<detail::MT19937>>
template<class Iterator >

RandomNumberGenerator | ( | Iterator | init,
|  | UInt32 | length
| ) |  |

Create a new random generator object from the given seed sequence.

Longer seed sequences lead to better initialization in the sense that the generator's state space is covered much better than is possible with 32-bit seeds alone.

## Member Function Documentation

## ◆ seed() [1/3]

template<class Engine = detail::RandomState<detail::MT19937>>

void seed | ( | RandomSeedTag |  | ) |

Re-initialize the random generator object with a random seed.

The seed is obtained from the machines current `clock()` and `time()` values.

Usage:

RandomNumberGenerator<> rnd = ...;
...
rnd.seed(RandomSeed);

## ◆ seed() [2/3]

template<class Engine = detail::RandomState<detail::MT19937>>

void seed | ( | UInt32 | theSeed,
|  | bool | ignoreSeed = `false`
| ) |  |

Re-initialize the random generator object from the given seed.

The same seed will always produce identical random sequences. If ignoreSeed is `true`, the given seed is ignored, and the generator is seeded randomly (as if `seed(RandomSeed)` was called). This allows you to switch between random and deterministic seeding at run-time.

## ◆ seed() [3/3]

template<class Engine = detail::RandomState<detail::MT19937>>
template<class Iterator >

void seed | ( | Iterator | init,
|  | UInt32 | length
| ) |  |

Re-initialize the random generator object from the given seed sequence.

Longer seed sequences lead to better initialization in the sense that the generator's state space is covered much better than is possible with 32-bit seeds alone.

## ◆ operator()()

template<class Engine = detail::RandomState<detail::MT19937>>

UInt32 operator() | ( |  | ) | const

Return a uniformly distributed integer random number in [0, 232).

That is, 0 <= i < 232.

## ◆ uniformInt() [1/2]

template<class Engine = detail::RandomState<detail::MT19937>>

UInt32 uniformInt | ( |  | ) | const

Return a uniformly distributed integer random number in [0, 232).

That is, 0 <= i < 232.

## ◆ uniformInt() [2/2]

template<class Engine = detail::RandomState<detail::MT19937>>

UInt32 uniformInt | ( | UInt32 | beyond | ) | const

Return a uniformly distributed integer random number in [0, `beyond`).

That is, 0 <= i < `beyond`.

## ◆ uniform53()

template<class Engine = detail::RandomState<detail::MT19937>>

double uniform53 | ( |  | ) | const

Return a uniformly distributed double-precision random number in [0.0, 1.0).

That is, 0.0 <= i < 1.0. All 53-bit bits of the mantissa are random (two 32-bit integers are used to create this number).

## ◆ uniform() [1/2]

template<class Engine = detail::RandomState<detail::MT19937>>

double uniform | ( |  | ) | const

Return a uniformly distributed double-precision random number in [0.0, 1.0].

That is, 0.0 <= i <= 1.0. This number is computed by `uniformInt()` / (232 - 1), so it has effectively only 32 random bits.

## ◆ uniform() [2/2]

template<class Engine = detail::RandomState<detail::MT19937>>

double uniform | ( | double | lower,
|  | double | upper
| ) |  | const

Return a uniformly distributed double-precision random number in [lower, upper].

That is, `lower` <= i <= `upper`. This number is computed from `uniform()`, so it has effectively only 32 random bits.

## ◆ normal() [1/2]

template<class Engine >

double normal | ( |  | ) | const

Return a standard normal variate (Gaussian) random number.

Mean is zero, standard deviation is 1.0. It uses the polar form of the Box-Muller transform.

## ◆ normal() [2/2]

template<class Engine = detail::RandomState<detail::MT19937>>

double normal | ( | double | mean,
|  | double | stddev
| ) |  | const

Return a normal variate (Gaussian) random number with the given mean and standard deviation.

It uses the polar form of the Box-Muller transform.

## ◆ global()

template<class Engine = detail::RandomState<detail::MT19937>>

static RandomNumberGenerator & global | ( |  | ) |

static

Access the global (program-wide) instance of the present random number generator.

Normally, you will create a local generator by one of the constructor calls. But sometimes it is useful to have all program parts access the same generator.

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

- vigra/random.hxx

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.11.1