Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template inversive_congruential_engine

boost::random::inversive_congruential_engine

Synopsis

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

template<typename IntType,  a,  b,  p> 
class inversive_congruential_engine {
public:
  // types
  typedef  ;

  // construct/copy/destruct
  ();
  ();
  template<typename SeedSeq> ();
  template<typename It> (, );

  // public static functions
   ();
   ();

  // public member functions
   ();
   ();
  template<typename SeedSeq>  ();
  template<typename It>  (, );
   ();
  template<typename Iter>  (, );
   ();

  // friend functions
  template<typename CharT, typename Traits> 
     
    (, 
               inversive_congruential_engine &);
  template<typename CharT, typename Traits> 
     
    (, 
               inversive_congruential_engine &);
   (inversive_congruential_engine &, 
                  inversive_congruential_engine &);
   (inversive_congruential_engine &, 
                  inversive_congruential_engine &);

  // public data members
  static  has_fixed_range;
  static  multiplier;
  static  increment;
  static  modulus;
  static  default_seed;
};

Description

Instantiations of class template inversive_congruential_engine 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. ftp://random.mat.sbg.ac.at/pub/data/wsc95.ps

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_engine public construct/copy/destruct

  1. ();

    Constructs an inversive_congruential_engine, seeding it with the default seed.

  2. ( x0);

    Constructs an inversive_congruential_engine, seeding it with x0.

  3. template<typename SeedSeq> 
      ( seq);

    Constructs an inversive_congruential_engine, seeding it with values produced by a call to seq.generate().

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

    Constructs an inversive_congruential_engine, 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.

inversive_congruential_engine public static functions

  1.  ();
  2.  ();

inversive_congruential_engine public member functions

  1.  ();

    Calls seed(default_seed)

  2.  ( x0);

    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).

  3. template<typename SeedSeq>  ( seq);

    Seeds an inversive_congruential_engine using values from a SeedSeq.

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

    seeds an inversive_congruential_engine 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.

  5.  ();

    Returns the next output of the generator.

  6. template<typename Iter>  ( first,  last);

    Fills a range with random values

  7.  ( z);

    Advances the state of the generator by z.

inversive_congruential_engine friend functions

  1. template<typename CharT, typename Traits> 
       
      ( os, 
                 inversive_congruential_engine & x);

    Writes the textual representation of the generator to a std::ostream.

  2. template<typename CharT, typename Traits> 
       
      ( is, 
                 inversive_congruential_engine & x);

    Reads the textual representation of the generator from a std::istream.

  3.  (inversive_congruential_engine & x, 
                    inversive_congruential_engine & y);

    Returns true if the two generators will produce identical sequences of outputs.

  4.  (inversive_congruential_engine & lhs, 
                    inversive_congruential_engine & rhs);

    Returns true if the two generators will produce different sequences of outputs.


PrevUpHomeNext