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 linear_congruential

boost::random::linear_congruential

Synopsis

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

template<typename IntType, IntType a, IntType c, IntType m, IntType val> 
class linear_congruential {
public:
  // types
  typedef IntType result_type;

  // construct/copy/destruct
  linear_congruential(IntType = 1);
  template<typename It> linear_congruential(It &, It);

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

  // public static functions
  static bool validation(IntType) ;
  static const bool has_fixed_range;
  static const result_type min_value;
  static const result_type max_value;
  static const IntType multiplier;
  static const IntType increment;
  static const IntType modulus;
};

Description

Instantiations of class template linear_congruential model a pseudo-random number generator . Linear congruential pseudo-random number generators are described in:

"Mathematical methods in large-scale computing units", D. H. Lehmer, Proc. 2nd Symposium on Large-Scale Digital Calculating Machines, Harvard University Press, 1951, pp. 141-146

Let x(n) denote the sequence of numbers returned by some pseudo-random number generator. Then for the linear congruential generator, x(n+1) := (a * x(n) + c) mod m. Parameters for the generator are x(0), a, c, m. The template parameter IntType shall denote an integral type. It must be large enough to hold values a, c, and m. The template parameters a and c must be smaller than m.

Note: The quality of the generator crucially depends on the choice of the parameters. User code should use one of the sensibly parameterized generators such as minstd_rand instead.

linear_congruential public construct/copy/destruct

  1. linear_congruential(IntType x0 = 1);

    Constructs a linear_congruential generator, seeding it with x0.

  2. template<typename It> linear_congruential(It & first, It last);

    Constructs a linear_congruential generator and seeds it with values taken from the itrator range [first, last) and adjusts first to point to the element after the last one used. If there are not enough elements, throws std::invalid_argument.

    first and last must be input iterators.

linear_congruential public member functions

  1. void seed(IntType x0 = 1) ;

    If c mod m is zero and x0 mod m is zero, changes the current value of the generator to 1. Otherwise, changes it to x0 mod m. If c is zero, distinct seeds in the range [1,m) will leave the generator in distinct states. If c is not zero, the range is [0,m).

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

    seeds a linear_congruential generator with values taken from the itrator range [first, last) and adjusts first to point to the element after the last one used. If there are not enough elements, throws std::invalid_argument.

    first and last must be input iterators.

  3. result_type min() const;

    Returns the smallest value that the linear_congruential generator can produce.

  4. result_type max() const;

    Returns the largest value that the linear_congruential generator can produce.

  5. IntType operator()() ;

    Returns the next value of the linear_congruential generator.

linear_congruential public static functions

  1. static bool validation(IntType x) ;

PrevUpHomeNext