Repository navigation
Closed
Description
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, andadvance(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
SeedSequenceand the carry is set to one, as suggested by the reference code; settingstatedirectly accepts any valid state. - Tests. Output,
jumped()andadvance()checked against the reference C code, also with the portable multiplication.
If you're interested, I'll open a PR.
Metadata
Metadata
Assignees
Labels
No labels
Activity
bashtage commentedon Nov 2, 2026
Happy for it to be included.