Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class mwc128x32

boost::random::mwc128x32

Synopsis

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


class mwc128x32 {
public:

  // private static functions
  static words_type modulus() noexcept;

  // public member functions
  result_type next() noexcept;
};

Description

This is MWC128X/32, a scrambled multiply-with-carry generator with 32-bit digits, lag three, and period approximately 2^127, from "Scrambled Multiply-with-Carry Pseudorandom Number Generators" by Sebastiano Vigna (https://arxiv.org/abs/2610.27313). It returns 32-bit values, it is recommended for all purposes, and it passes all tests we are aware of. It needs just a 32 x 32 -> 64-bit multiplication.

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 = 0xffcccc66 * 2^96 - 1 and multiplier 2^(-32) 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, 64) is equivalent to the jump() function of the reference implementation: it can be used to generate 2^63 non-overlapping subsequences for parallel computations. jump(1, 96) is equivalent to long_jump(): it can be used to generate 2^31 starting points, from each of which jump(1, 64) will generate 2^32 non-overlapping subsequences for parallel distributed computations.

The state is formed by three 32-bit digits x, y, z and a 32-bit carry c, and it is read as the integer x + y * 2^32 + z * 2^64 + c * 2^96, which must be nonzero and smaller than m. This generator is not suitable for cryptographic purposes.

mwc128x32 private static functions

  1. static words_type modulus() noexcept;

mwc128x32 public member functions

  1. result_type next() noexcept;

PrevUpHomeNext