Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

Class template lagged_fibonacci_01_engine

boost::random::lagged_fibonacci_01_engine

Synopsis

// In header: <boost/random/lagged_fibonacci.hpp>

template<typename RealType, int w, unsigned int p, unsigned int q> 
class lagged_fibonacci_01_engine {
public:
  // types
  typedef RealType result_type;

  // construct/copy/destruct
  lagged_fibonacci_01_engine();
  explicit lagged_fibonacci_01_engine(uint32_t);
  template<typename SeedSeq> explicit lagged_fibonacci_01_engine(SeedSeq &);
  template<typename It> lagged_fibonacci_01_engine(It &, It);

  // public member functions
  void seed();
  void seed(boost::uint32_t);
  template<typename SeedSeq> void seed(SeedSeq &);
  template<typename It> void seed(It &, It);
  result_type operator()();
  template<typename Iter> void generate(Iter, Iter);
  void discard(boost::uintmax_t);

  // public static functions
  static constexpr result_type min();
  static constexpr result_type max();

  // friend functions
  template<typename CharT, typename Traits> 
    friend std::basic_ostream< CharT, Traits > & 
    operator<<(std::basic_ostream< CharT, Traits > &, 
               const lagged_fibonacci_01_engine &);
  template<typename CharT, typename Traits> 
    friend std::basic_istream< CharT, Traits > & 
    operator>>(std::basic_istream< CharT, Traits > &, 
               const lagged_fibonacci_01_engine &);
  friend bool operator==(const lagged_fibonacci_01_engine &, 
                         const lagged_fibonacci_01_engine &);
  friend bool operator!=(const lagged_fibonacci_01_engine &, 
                         const lagged_fibonacci_01_engine &);

  // public data members
  static const bool has_fixed_range;
  static const int word_size;
  static const unsigned int long_lag;
  static const unsigned int short_lag;
  static const boost::uint32_t default_seed;
};

Description

Instantiations of class template lagged_fibonacci_01 model a pseudo-random number generator . It uses a lagged Fibonacci algorithm with two lags p and q, evaluated in floating-point arithmetic: x(i) = x(i-p) + x(i-q) (mod 1) with p > q. See

"Uniform random number generators for supercomputers", Richard Brent, Proc. of Fifth Australian Supercomputer Conference, Melbourne, Dec. 1992, pp. 704-706.

[Note] Note

The quality of the generator crucially depends on the choice of the parameters. User code should employ one of the sensibly parameterized generators such as lagged_fibonacci607 instead.

The generator requires considerable amounts of memory for the storage of its state array. For example, lagged_fibonacci607 requires about 4856 bytes and lagged_fibonacci44497 requires about 350 KBytes.

lagged_fibonacci_01_engine public construct/copy/destruct

  1. lagged_fibonacci_01_engine();

    Constructs a lagged_fibonacci_01 generator and calls seed().

  2. explicit lagged_fibonacci_01_engine(uint32_t value);

    Constructs a lagged_fibonacci_01 generator and calls seed(value).

  3. template<typename SeedSeq> explicit lagged_fibonacci_01_engine(SeedSeq & seq);

    Constructs a lagged_fibonacci_01 generator and calls seed(gen).

  4. template<typename It> lagged_fibonacci_01_engine(It & first, It last);

lagged_fibonacci_01_engine public member functions

  1. void seed();

    Calls seed(default_seed).

  2. void seed(boost::uint32_t value);

    Constructs a minstd_rand0 generator with the constructor parameter value and calls seed with it. Distinct seeds in the range [1, 2147483647) will produce generators with different states. Other seeds will be equivalent to some seed within this range. See linear_congruential_engine for details.

  3. template<typename SeedSeq> void seed(SeedSeq & seq);

    Seeds this lagged_fibonacci_01_engine using values produced by seq.generate.

  4. template<typename It> void seed(It & first, It last);

    Seeds this lagged_fibonacci_01_engine using values from the iterator range [first, last). If there are not enough elements in the range, throws std::invalid_argument.

  5. result_type operator()();

    Returns the next value of the generator.

  6. template<typename Iter> void generate(Iter first, Iter last);

    Fills a range with random values

  7. void discard(boost::uintmax_t z);

    Advances the state of the generator by z.

lagged_fibonacci_01_engine public static functions

  1. static constexpr result_type min();

    Returns the smallest value that the generator can produce.

  2. static constexpr result_type max();

    Returns the upper bound of the generators outputs.

lagged_fibonacci_01_engine friend functions

  1. template<typename CharT, typename Traits> 
      friend std::basic_ostream< CharT, Traits > & 
      operator<<(std::basic_ostream< CharT, Traits > & os, 
                 const lagged_fibonacci_01_engine & f);

    Writes the textual representation of the generator to a std::ostream.

  2. template<typename CharT, typename Traits> 
      friend std::basic_istream< CharT, Traits > & 
      operator>>(std::basic_istream< CharT, Traits > & is, 
                 const lagged_fibonacci_01_engine & f);

    Reads the textual representation of the generator from a std::istream.

  3. friend bool operator==(const lagged_fibonacci_01_engine & x_, 
                           const lagged_fibonacci_01_engine & y_);

    Returns true if the two generators will produce identical sequences of outputs.

  4. friend bool operator!=(const lagged_fibonacci_01_engine & lhs, 
                           const lagged_fibonacci_01_engine & rhs);

    Returns true if the two generators will produce different sequences of outputs.


PrevUpHomeNext