| Home | Libraries | People | FAQ | More

## Class template lagged_fibonacci

boost::random::lagged_fibonacci

## Synopsis

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

    template<typename UIntType, int w, unsigned int p, unsigned int q,
             UIntType val = 0>
    class lagged_fibonacci {
    public:
      // types
      typedef UIntType result_type;

      // construct/copy/destruct
      lagged_fibonacci();
      lagged_fibonacci(uint32_t);
      template<typename It> lagged_fibonacci(It &, It);

      // public member functions
      result_type min() const;
      result_type max() const;
      void seed(uint32_t = 331u);
      template<typename It> void seed(It &, It);
      result_type operator()();

      // public static functions
      static bool validation(result_type);
      static const bool has_fixed_range;
      static const int word_size;
      static const unsigned int long_lag;
      static const unsigned int short_lag;
    };

## Description

Instantiations of class template lagged_fibonacci model a pseudo-random number generator . It uses a lagged Fibonacci algorithm with two lags `p` and `q:` x(i) = x(i-p) + x(i-q) (mod 2w) with p > q.

### `lagged_fibonacci` public construct/copy/destruct

1.     lagged_fibonacci();

   Creates a new `lagged_fibonacci` generator and calls `seed()`

2.     lagged_fibonacci(uint32_t value);

   Creates a new `lagged_fibonacci` generator and calls `seed(value)`

3.     template<typename It> lagged_fibonacci(It & first, It last);

   Creates a new `lagged_fibonacci` generator and calls `seed(first, last)`

### `lagged_fibonacci` public member functions

1.     result_type min() const;

   Returns: the smallest value that the generator can produce

2.     result_type max() const;

   Returns: the largest value that the generator can produce

3.     void seed(uint32_t value = 331u);

   Sets the state of the generator to values produced by a `minstd_rand` generator.

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

   Sets the state of the generator to values from the iterator range [first, last). If there are not enough elements in the range [first, last) throws `std::invalid_argument`.

5.     result_type operator()();

   Returns: the next value of the generator

### `lagged_fibonacci` public static functions

1.     static bool validation(result_type x);