+ typedef MLCG1 first_base;
+ typedef MLCG2 second_base;
+ typedef typename MLCG1::result_type result_type;
+
+ // Required by old Boost.Random concept
+ BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
+ /**
+ * Returns the smallest value that the generator can produce
+ */
+ static result_type min BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ { return 1; }
+ /**
+ * Returns the largest value that the generator can produce
+ */
+ static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ { return MLCG1::modulus-1; }
+
+ /**
+ * Constructs an @c additive_combine_engine using the
+ * default constructors of the two base generators.
+ */
+ additive_combine_engine() : _mlcg1(), _mlcg2() { }
+ /**
+ * Constructs an @c additive_combine_engine, using seed as
+ * the constructor argument for both base generators.
+ */
+ BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(additive_combine_engine,
+ result_type, seed_arg)
+ {
+ _mlcg1.seed(seed_arg);
+ _mlcg2.seed(seed_arg);
+ }
+ /**
+ * Constructs an @c additive_combine_engine, using seq as
+ * the constructor argument for both base generators.
+ *
+ * @xmlwarning
+ * The semantics of this function are liable to change.
+ * A @c seed_seq is designed to generate all the seeds
+ * in one shot, but this seeds the two base engines
+ * independantly and probably ends up giving the same
+ * sequence to both.
+ * @endxmlwarning
+ */
+ BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(additive_combine_engine,
+ SeedSeq, seq)
+ {
+ _mlcg1.seed(seq);
+ _mlcg2.seed(seq);
+ }
+ /**
+ * Constructs an @c additive_combine_engine, using
+ * @c seed1 and @c seed2 as the constructor argument to
+ * the first and second base generators, respectively.
+ */
+ additive_combine_engine(typename MLCG1::result_type seed1,
+ typename MLCG2::result_type seed2)
+ : _mlcg1(seed1), _mlcg2(seed2) { }
+ /**
+ * Contructs an @c additive_combine_engine 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: @c std::invalid_argument if the input range is too small.
+ *
+ * Exception Safety: Basic
+ */
+ template<class It> additive_combine_engine(It& first, It last)
+ : _mlcg1(first, last), _mlcg2(first, last) { }
+
+ /**
+ * Seeds an @c additive_combine_engine using the default
+ * seeds of the two base generators.
+ */
+ void seed()
+ {
+ _mlcg1.seed();
+ _mlcg2.seed();
+ }
+
+ /**
+ * Seeds an @c additive_combine_engine, using @c seed as the
+ * seed for both base generators.
+ */
+ BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(additive_combine_engine,
+ result_type, seed_arg)
+ {
+ _mlcg1.seed(seed_arg);
+ _mlcg2.seed(seed_arg);
+ }
+
+ /**
+ * Seeds an @c additive_combine_engine, using @c seq to
+ * seed both base generators.
+ *
+ * See the warning on the corresponding constructor.
+ */
+ BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(additive_combine_engine,
+ SeedSeq, seq)
+ {
+ _mlcg1.seed(seq);
+ _mlcg2.seed(seq);
+ }
+
+ /**
+ * Seeds an @c additive_combine generator, using @c seed1 and @c seed2 as
+ * the seeds to the first and second base generators, respectively.
+ */
+ void seed(typename MLCG1::result_type seed1,
+ typename MLCG2::result_type seed2)
+ {
+ _mlcg1.seed(seed1);
+ _mlcg2.seed(seed2);
+ }
+
+ /**
+ * Seeds an @c additive_combine_engine 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: @c std::invalid_argument if the input range is too small.
+ *
+ * Exception Safety: Basic
+ */
+ template<class It> void seed(It& first, It last)
+ {
+ _mlcg1.seed(first, last);
+ _mlcg2.seed(first, last);
+ }
+
+ /** Returns the next value of the generator. */
+ result_type operator()() {
+ result_type val1 = _mlcg1();
+ result_type val2 = _mlcg2();
+ if(val2 < val1) return val1 - val2;
+ else return val1 - val2 + MLCG1::modulus - 1;
+ }
+
+ /** Fills a range with random values */
+ template<class Iter>
+ void generate(Iter first, Iter last)
+ { detail::generate_from_int(*this, first, last); }
+
+ /** Advances the state of the generator by @c z. */
+ void discard(boost::uintmax_t z)
+ {
+ _mlcg1.discard(z);
+ _mlcg2.discard(z);
+ }
+
+ /**
+ * Writes the state of an @c additive_combine_engine to a @c
+ * std::ostream. The textual representation of an @c
+ * additive_combine_engine is the textual representation of
+ * the first base generator followed by the textual representation
+ * of the second base generator.
+ */
+ BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, additive_combine_engine, r)
+ { os << r._mlcg1 << ' ' << r._mlcg2; return os; }
+
+ /**
+ * Reads the state of an @c additive_combine_engine from a
+ * @c std::istream.
+ */
+ BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, additive_combine_engine, r)
+ { is >> r._mlcg1 >> std::ws >> r._mlcg2; return is; }
+
+ /**
+ * Returns: true iff the two @c additive_combine_engines will
+ * produce the same sequence of values.
+ */
+ BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(additive_combine_engine, x, y)
+ { return x._mlcg1 == y._mlcg1 && x._mlcg2 == y._mlcg2; }
+ /**
+ * Returns: true iff the two @c additive_combine_engines will
+ * produce different sequences of values.
+ */
+ BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(additive_combine_engine)
+
+private:
+ MLCG1 _mlcg1;
+ MLCG2 _mlcg2;
+};
+