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

This is an old version of boost. Click here for the latest version's documentation home page.

Class template inversive_congruential



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

template<typename IntType, IntType a, IntType b, IntType p, IntType val> 
class inversive_congruential {
  // types
  typedef IntType result_type;

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

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

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


Instantiations of class template inversive_congruential model a pseudo-random number generator . It uses the inversive congruential algorithm (ICG) described in

"Inversive pseudorandom number generators: concepts, results and links", Peter Hellekalek, In: "Proceedings of the 1995 Winter Simulation Conference", C. Alexopoulos, K. Kang, W.R. Lilegdon, and D. Goldsman (editors), 1995, pp. 255-262.

The output sequence is defined by x(n+1) = (a*inv(x(n)) - b) (mod p), where x(0), a, b, and the prime number p are parameters of the generator. The expression inv(k) denotes the multiplicative inverse of k in the field of integer numbers modulo p, with inv(0) := 0.

The template parameter IntType shall denote a signed integral type large enough to hold p; a, b, and p are the parameters of the generators. The template parameter val is the validation value checked by validation.

[Note] Note

The implementation currently uses the Euclidian Algorithm to compute the multiplicative inverse. Therefore, the inversive generators are about 10-20 times slower than the others (see section"performance"). However, the paper talks of only 3x slowdown, so the Euclidian Algorithm is probably not optimal for calculating the multiplicative inverse.

inversive_congruential public construct/copy/destruct

  1. inversive_congruential(IntType y0 = 1);

    Constructs an inversive_congruential generator with y0 as the initial state.

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

inversive_congruential public member functions

  1. result_type min() const;
  2. result_type max() const;
  3. void seed(IntType y0 = 1);

    Changes the current state to y0.

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

inversive_congruential public static functions

  1. static bool validation(result_type x);