arXiv:2610.27313cs.CROct 2026

Manuscript Offprint

arXiv:2610.27313

Scrambled Multiply-with-Carry Pseudorandom Number Generators

Sebastiano Vigna

SEBASTIANO VIGNA, Università degli Studi di Milano, Italy

Multiply-with-carry (MWC) generators are very fast pseudorandom number generators whose quality depends on the choice of a multiplier, and is usually assessed by applying the spectral test to an associated multiplicative congruential generator. We show that the special form of the modulus imposes structural limitations on the lattice structure of every MWC generator, which the generalized MWC generators of Goresky and Klapper mitigate; in our tests, xoring each output with its carry removes them. Since these limitations make the usual worst-case criterion useless, we rank candidates by a weighted geometric mean of their figures of merit, which does not depend on their normalization, and suggest multipliers for generators with 64 to 256 bits of state. Along the way, we correct some errors in the literature. In the end, we propose MWC192X, a 64-bit generator with 192 bits of state that passes all tests we are aware of, and emits an output in half a nanosecond.

CCS Concepts: • Mathematics of computing → Random number generation.

Additional Key Words and Phrases: Pseudorandom number generators, multiply-with-carry, spectral test

1 Introduction

Congruential generators are among the oldest and best understood pseudorandom number generators (PRNGs): their outputs have a lattice structure that can be analyzed precisely with number-theoretic tools [17]. This paper is about a family of very fast generators whose analysis reduces to that of congruential generators: generators with carry.

Marsaglia and Zaman [31] introduced in 1991 add-with-carry (AWC) and subtract-with-borrow (SWB) generators, which extend lagged Fibonacci generators by propagating a carry (or borrow). Tezuka, L'Ecuyer, and Couture [37] showed that they are, in disguise, multiplicative congruential generators (MCGs) with a huge modulus, whose lattice structure is very bad in dimensions larger than the lag (see also [3]), a defect that Lüscher's RANLUX generator [28] mitigates by discarding most of the outputs.

In 1994, Marsaglia [29] proposed multiply-with-carry (MWC) generators, in which the sum of two lagged values is replaced by a linear combination of lagged values. Couture and L'Ecuyer [4, 5] showed that they, too, simulate an MCG: when only one coefficient aa is nonzero, if bb is the base (typically, 2322^{32} or 2642^{64}) and kk is the lag, the modulus is m=abk−1m = ab^k - 1 and the multiplier is b−1mod  mb^{-1} \mod m. They also introduced complementary MWC generators, with modulus abk+1ab^k + 1, later popularized by Marsaglia [30]. Independently, Klapper and Goresky [14, 15] studied feedback with carry shift registers (FCSRs), the binary analogue of MWC generators, using 2-adic numbers. Goresky and Klapper [12] later merged the two points of view, and proposed a generalized MWC (GMWC) generator, in which the new digit is multiplied by a coefficient a0a_0 coprime with the base [16], so that the modulus can have a much less constrained form.

On 64-bit architectures with fast 64×64→12864 \times 64 \rightarrow 128-bit multiplications, MWC generators are a very interesting choice: an MWC generator with 128 bits of state needs one full multiplication and one addition, and has period about 21272^{127}; when the lag is larger than one, the multiplications of consecutive outputs are independent, and modern processors execute them in parallel (Section 8.3). The author has been distributing MWC and GMWC generators for a few years, 1^{1} and since version

1^{1}https://prng.di.unimi.it/

Author's Contact Information: Sebastiano Vigna, Università degli Studi di Milano, Dipartimento di Informatica, Milano, Italy, vigna@acm.org.

Sebastiano Vigna

25.0 Erlang/OTP includes a 59-bit MWC generator whose multiplier was selected by the author and Raimo Niskanen [9] (Section 8.1).

The quality of an MWC generator depends on the multiplier aa, and the natural tool to assess it is the spectral test [6, 17] of the associated MCG, which computes, in each dimension tt, the maximal distance dtd_t between successive hyperplanes over all families of equidistant parallel hyperplanes covering the points produced by the generator. The distances are normalized into figures of merit ft∈(0…1]f_t \in (0 \dots 1], which are summarized by a single criterion, such as their minimum, the worst-case figure of merit MTM_T [10, 19], or the harmonic score of Steele and Vigna [36]. The form of the modulus of an MWC generator, however, forces a bad lattice structure: in dimensions up to k+1k + 1 the figures of merit are fixed by the parameters, and in dimension k+2k + 2 they are, as we show, smaller than 10−310^{-3} for b=264b = 2^{64}, so the worst-case figure of merit is determined by a single, structurally bad dimension.

Our main result makes this limitation explicit: whatever the lag kk and the multiplier a<ba < b, the vectors of outputs (xn,xn+1,xn+k+1)/b(x_n, x_{n+1}, x_{n+k+1})/b of an MWC generator lie, up to an error smaller than 1/b1/b in each coordinate, in a family of equidistant parallel planes at least about 1/(1.28b)1/(1.28\sqrt{b}) apart (Section 4.2; the argument is similar to that used by L'Ecuyer and coauthors for multiple recursive generators with few nonzero coefficients [26, 27]). The resulting bounds on the figures of merit are nearly attained by our best multipliers and, together with a generalization, explain all the structural limitations we observe. A three-dimensional birthday-spacings test detects the defect in a few seconds for b=232b = 2^{32}, but for b=264b = 2^{64} it needs about 3 TB of output and an implementation that can process them independently of the available memory: in our opinion, this makes the defect irrelevant in practice.

GMWC generators with lag larger than one have a similar defect, with planes about b−2/3b^{-2/3} apart, whereas for GMWC generators with lag one we find multipliers with excellent figures of merit in all the dimensions we consider. In any case, the scrambler X, which generalizes to GMWC generators that of Thomas's MWC64X generator (the exclusive or of each digit with the corresponding carry), removes, in our tests, the defect and every other form of lattice structure we could detect (Section 5).

Since the worst-case figure of merit is useless, we rank candidates by a weighted geometric mean of their figures of merit: by a classical characterization from social choice theory [7], this is essentially the only ranking that depends neither on the normalization of the figures of merit nor on the other candidates (Section 6). We report the results of a search over more than 52 million candidates for nine combinations of base, lag, and generator type, and suggest multipliers. Our final suggested generator is MWC192X: on x86-64 processors, MWC192X and MWC256X are the fastest scalar generators known to the author that have a known period and jump functions, and pass all the statistical tests we are aware of (Section 8.4). We suggest also 32-bit generators.

We give a self-contained presentation of (G)MWC generators based on b-adic numbers, following Goresky and Klapper [12], with simple seeding instructions for GMWC generators, and we correct three errors in [12]: the formula for the carry is incorrect when a0≠1a_0 \neq 1, three of the twelve proposed parameter sets do not have maximum period, and the exponential representation of the output has the wrong sign (a related error appears in [13]). Finally, our title nods to the scrambled linear generators of Blackman and Vigna [1]: our generators, too, are made of an engine and a scrambler, but the engine is based on congruential arithmetic rather than on F2F_2-linear maps, and, dually, our scrambler uses F2F_2-based rather than congruential arithmetic.

The examined candidate multipliers and their spectral data are available at https://vigna.di.unimi.it/MWC.tar.zst.

References (29)