![]() |
Home | Libraries | People | FAQ | More |
boost::random::mwc192x
// In header: <boost/random/mwcx.hpp> class mwc192x { public: // private static functions static words_type modulus() noexcept; // public member functions result_type next() noexcept; };
This is MWC192X, a scrambled multiply-with-carry generator with 64-bit digits, lag two, and period approximately 2^191, from "Scrambled Multiply-with-Carry Pseudorandom Number Generators" by Sebastiano Vigna (https://arxiv.org/abs/2610.27313). It is recommended for all purposes: it is one of the fastest generators available and it passes all tests we are aware of. Its only 128-bit operations are a multiplication and a sum, and, since the lag is two, each multiplication uses a digit computed two steps before, so the processor can overlap the multiplications of consecutive steps.
The output is scrambled by X: it is the most recent digit xored with the carry, as in David Thomas's MWC64X generator. The underlying generator simulates a multiplicative congruential generator with prime modulus m = 0xff4e24dd418f5433 * 2^128 - 1 and multiplier 2^(-64) mod m.
discard() computes the state up to 2^64 - 1 steps ahead in time logarithmic in the number of steps, and jump(c, e) advances the generator by c * 2^e steps, which makes it possible to obtain non-overlapping subsequences at distances larger than discard() can express. jump(1, 96) is equivalent to the jump() function of the reference implementation: it can be used to generate 2^95 non-overlapping subsequences for parallel computations. jump(1, 144) is equivalent to long_jump(): it can be used to generate 2^47 starting points, from each of which jump(1, 96) will generate 2^48 non-overlapping subsequences for parallel distributed computations.
The state is formed by two 64-bit digits x and y and a 64-bit carry c, and it is read as the integer x + y * 2^64 + c * 2^128, which must be nonzero and smaller than m. This generator is not suitable for cryptographic purposes.