ALPS Home Libraries License Support People ALPS Web Site

PrevUpHomeNext

Class buffered_rng_base

alps::buffered_rng_base — abstract base class of a runtime-polymorphic random number generator

Synopsis

// In header: <alps/random/buffered_rng.h>


class buffered_rng_base {
public:
  // types
  typedef uint32_t                   result_type;  // we create random numbers of type uint32_t 
  typedef std::vector< result_type > buffer_type;

  // construct/copy/destruct
  buffered_rng_base(std::size_t = 10240);
  buffered_rng_base(const buffered_rng_base &);
  ~buffered_rng_base();

  // public member functions
   BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
  result_type operator()();
  template<typename OutputIterator> 
    OutputIterator generate_n(std::size_t, OutputIterator);
  void seed(uint32_t);
  void seed();
  void seed(pseudo_des &);
  void write(std::ostream &) const;
  void read(std::istream &);
  void write_all(std::ostream &) const;
  void read_all(std::istream &);
  result_type min BOOST_PREVENT_MACRO_SUBSTITUTION() const;
  result_type max BOOST_PREVENT_MACRO_SUBSTITUTION() const;

  // private member functions
  void fill_buffer();
};

Description

In order to mask the abstraction penalty, the derived generators do not produce single random numbers at each call, but instead a large buffer is filled in a virtual function call, and then numbers from this buffer used when operator() is called.

buffered_rng_base public construct/copy/destruct

  1. buffered_rng_base(std::size_t b = 10240);
    the constructor

    Parameters:

    b

    the size of the buffer

  2. buffered_rng_base(const buffered_rng_base & gen);
  3. ~buffered_rng_base();

buffered_rng_base public member functions

  1.  BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
  2. result_type operator()();
    returns the next random number

    numbers are taken from the buffer, which is refilled by a call to fill_buffer when it gets empty

  3. template<typename OutputIterator> 
      OutputIterator generate_n(std::size_t n, OutputIterator it);
  4. void seed(uint32_t);
    seed with an unsigned integer
  5. void seed();
    seed with the default value
  6. void seed(pseudo_des & inigen);
    seed with the pseudo_des generator
  7. void write(std::ostream &) const;
    write the state to a std::ostream
  8. void read(std::istream &);
    read the state from a std::istream
  9. void write_all(std::ostream & os) const;
    write the full state (including buffer) to a std::ostream
  10. void read_all(std::istream &);
    read the full state (including buffer) from a std::istream
  11. result_type min BOOST_PREVENT_MACRO_SUBSTITUTION() const;
  12. result_type max BOOST_PREVENT_MACRO_SUBSTITUTION() const;

buffered_rng_base private member functions

  1. void fill_buffer();
    refills the buffer
Copyright © 2006-2008 Brigitte Surer, Matthias Troyer

PrevUpHomeNext