...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::random::inversive_congruential
// In header: <boost/random/inversive_congruential.hpp> template<typename IntType, IntType a, IntType b, IntType p, IntType val> class inversive_congruential { public: // 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. 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 | |
---|---|
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. |