Class template additive_combine

| Home | Libraries | People | FAQ | More

## Class template additive_combine

boost::random::additive_combine

## Synopsis

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

    template<typename MLCG1, typename MLCG2, typename MLCG1::result_type val>
    class additive_combine {
    public:
      // types
      typedef MLCG1              first_base;
      typedef MLCG2              second_base;
      typedef MLCG1::result_type result_type;

      // construct/copy/destruct
      additive_combine();
      additive_combine(result_type);
      additive_combine(typename MLCG1::result_type, typename MLCG2::result_type);
      template<typename It> additive_combine(It &, It);

      // public member functions
      result_type min() const;
      result_type max() const;
      void seed() ;
      void seed(result_type) ;
      void seed(typename MLCG1::result_type, typename MLCG2::result_type) ;
      template<typename It> void seed(It &, It) ;
      result_type operator()() ;

      // public static functions
      static bool validation(result_type) ;

      // friend functions
      template<typename CharT, typename Traits>
        friend std::basic_ostream< CharT, Traits > &
        operator<<(std::basic_ostream< CharT, Traits > &,
                   const additive_combine &) ;
      template<typename CharT, typename Traits>
        friend std::basic_istream< CharT, Traits > &
        operator>>(std::basic_istream< CharT, Traits > &, additive_combine &) ;
      friend bool operator==(const additive_combine &, const additive_combine &) ;
      friend bool operator!=(const additive_combine &, const additive_combine &) ;
      static const bool has_fixed_range;
      static const result_type min_value;
      static const result_type max_value;
    };

## Description

An instantiation of class template additive_combine model a pseudo-random number generator . It combines two multiplicative linear_congruential number generators, i.e. those with `c` = 0. It is described in

> "Efficient and Portable Combined Random Number Generators", Pierre L'Ecuyer, Communications of the ACM, Vol. 31, No. 6, June 1988, pp. 742-749, 774

The template parameters MLCG1 and MLCG2 shall denote two different linear_congruential number generators, each with c = 0. Each invocation returns a random number X(n) := (MLCG1(n) - MLCG2(n)) mod (m1 - 1), where m1 denotes the modulus of MLCG1.

The template parameter `val` is the validation value checked by validation.

### `additive_combine` public construct/copy/destruct

1.     additive_combine();

   Constructs an `additive_combine` generator using the default constructors of the two base generators.

2.     additive_combine(result_type aseed);

   Constructs an `additive_combine` generator, using aseed as the constructor argument for both base generators.

3.     additive_combine(typename MLCG1::result_type seed1,
                        typename MLCG2::result_type seed2);

   Constructs an `additive_combine` generator, using `seed1` and `seed2` as the constructor argument to the first and second base generators, respectively.

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

   Contructs an `additive_combine` generator with values from the range defined by the input iterators first and last. first will be modified to point to the element after the last one used.

   Throws: `std::invalid_argument` if the input range is too small.

   Exception Safety: Basic

### `additive_combine` 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() ;

   Seeds an `additive_combine` generator using the default seeds of the two base generators.

4.     void seed(result_type aseed) ;

   Seeds an `additive_combine` generator, using `aseed` as the seed for both base generators.

5.     void seed(typename MLCG1::result_type seed1,
                 typename MLCG2::result_type seed2) ;

   Seeds an `additive_combine` generator, using `seed1` and `seed2` as the seeds to the first and second base generators, respectively.

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

   Seeds an `additive_combine` generator with values from the range defined by the input iterators first and last. first will be modified to point to the element after the last one used.

   Throws: `std::invalid_argument` if the input range is too small.

   Exception Safety: Basic

7.     result_type operator()() ;

   Returns: the next value of the generator

### `additive_combine` public static functions

1.     static bool validation(result_type x) ;

### `additive_combine` friend functions

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

   Writes the state of an `additive_combine` generator to a `std::ostream`. The textual representation of an `additive_combine` generator is the textual representation of the first base generator followed by the textual representation of the second base generator.

2.     template<typename CharT, typename Traits>
         friend std::basic_istream< CharT, Traits > &
         operator>>(std::basic_istream< CharT, Traits > & is, additive_combine & r) ;

   Reads the state of an `additive_combine` generator from a `std::istream`.

3.     friend bool operator==(const additive_combine & x, const additive_combine & y) ;

   Returns: true iff the two `additive_combine` generators will produce the same sequence of values.

4.     friend bool operator!=(const additive_combine & x, const additive_combine & y) ;

   Returns: true iff the two `additive_combine` generators will produce different sequences of values.