ALPS Project

Header file random.h

This header contains helper functions to generically seed random number generators and a class for fast buffered random number generators, suitable for compile time polymorphism.

Synopsis

namespace alps {
template <class RNG>
void seed_with_sequence(RNG& rng, uint32_t seed);

template <class T=double>
class BufferedRandomNumberGeneratorBase
{
public:
  typedef T result_type;
  BufferedRandomNumberGeneratorBase(std::size_t b=10240);

  inline T operator()();

  virtual void seed(uint32_t) = 0;
  virtual void seed() =0;
};

template <class RNG> class BufferedRandomNumberGeneratorAdaptor
 : public BufferedRandomNumberGeneratorBase<typename RNG::result_type>
{
public:
  typedef typename RNG::result_type result_type;

  BufferedRandomNumberGeneratorAdaptor(RNG&& rng);
  
  template <class IT> void seed(IT start, IT end);
  void seed(uint32_t);
  void seed();
};

template <class RNG> class BufferedRandomNumberGenerator
 : public BufferedRandomNumberGeneratorAdaptor<typename RNG::result_type>
{
public:
  typedef typename RNG::result_type result_type;

  BufferedRandomNumberGenerator();
  BufferedRandomNumberGenerator(const RNG& r);
};

}

Function seed_with_sequence

The function
template <class RNG>
void seed_with_sequence(RNG& rng, uint32_t seed);
seeds a random number generator following the Boost library proposed for the next version of the C++ standard library with a unique sequence, initialized from the given seed using a Pseudo-DES generator. This allows generic seeding of all conforming random number generators.

Class BufferedRandomNumberGeneratorBase

is the abstract base class for buffered random number generators. A buffered random number generator generates a block of random numbers at a time, possibly achieving speedup by vectorizing or pipelining the generation. Access to random numbers is inlined and fast. This also allows using runtime polymorphism of the random number generator without much overhead.
typedef T result_type;
is the type of random numbers generated
BufferedRandomNumberGeneratorBase(std::size_t b=10240);
the buffer size is passed to the constructor.
inline T operator()();
returns the next random number.
virtual void seed(uint32_t) = 0;
seeds the generator with an integer seed.
virtual void seed() =0;
seeds the generator with the default seed.

Class BufferedRandomNumberGeneratorAdaptor

is an implementation of a buffered random number generator adaptor, taking a random number generator following the boost random number generator interface and converting it into a buffered generator.
typedef typename RNG::result_type result_type;
is the type of random numbers generated, taken from the base generator.
BufferedRandomNumberGeneratorAdaptor(RNG& rng);
The constructor takes the base generator as argument.
inline T operator()();
returns the next random number.
virtual void seed(uint32_t);
seeds the generator with an integer seed, using the function seed_with_sequence
virtual void seed();
seeds the generator with the default seed.
template <class IT> void seed(IT start, IT end);
seeds the generator from a buffer given by a pair if iterators, following the new Boost random number generator concepts proposed for the next revision of the C++ standard.

Class BufferedRandomNumberGenerator

is like BufferedRandomNumberGenerator but contains the base generator itself instead of a reference to it.
BufferedRandomNumberGenerator();
seeds the generator with its default seed.
BufferedRandomNumberGenerator(const RNG& rng);
seeds the generator with a copy of the argument.

copyright (c) 1994-2010 by Matthias Troyer

Distributed under the Boost Software License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt)