Skip to content

Proposal: generators from the MWCX family #448

Closed

Description

@vigna

I'd like to add four scrambled multiply-with-carry generators from "Scrambled Multiply-with-Carry Pseudorandom Number Generators", the same four that are being added to Boost (boostorg/random#171) and to the Rust rngs project (rust-random/rngs#125):

  • MWC192X: 64-bit outputs, 192 bits of state. Recommended for all purposes.
  • MWC128X: 64-bit outputs, 128 bits of state.
  • MWC128X32: 32-bit outputs, 128 bits of state. Recommended when 32-bit outputs are needed.
  • MWC64X32: 32-bit outputs, 64 bits of state, for environments in which registers are scarce.

These generators are really fast. They pass all tests I'm aware of (in particular, PractRand up to 32TB). The code would be a translation of the reference C implementations at https://github.com/vigna/MWCPRNG.

AMD EPYC 9R45 (Zen 5, 4.5 GHz), reference C code, ns per 64 bits (details)

Generator GCC 16.2 Clang 23.1
MWC192X 0.52 0.51
xoshiro256++ 0.58 0.58
xoroshiro128++ 0.66 0.69
MWC128X 0.94 0.95
MT19937-64 1.39 1.14

NVIDIA H100, ps per 32 bits for the whole GPU (details)

Generator ps
MWC64X/32 0.23
MWC128X/32 0.24
xoshiro128+ 0.37
xoshiro128++ 0.44
cuRAND XORWOW 0.36
cuRAND Philox4x32-10 0.81

Notes:

  • 128-bit product. unsigned __int128, _umul128 (MSVC x64), __umulh (MSVC ARM64), or a portable 32-bit schoolbook multiplication, so there would be no platform restrictions.
  • Jumps. jumped() as in the other generators, and advance(delta) for arbitrary distances in logarithmic time: the generators simulate a multiplicative congruential generator with prime modulus, so a jump is a modular multiplication of the state.
  • Seeding. The digits are filled from the SeedSequence and the carry is set to one, as suggested by the reference code; setting state directly accepts any valid state.
  • Tests. Output, jumped() and advance() checked against the reference C code, also with the portable multiplication.

If you're interested, I'll open a PR.

Activity

  1. bashtage commented on Nov 2, 2026

    @bashtage
    Owner

    Happy for it to be included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions