Further scramblings of Marsaglia’s xorshift generators
Sebastiano Vigna, Universit`a degli Studi di Milano, Italy
xorshift* generators are a variant of Marsaglia’s xorshift generators that eliminate linear artifacts typical
of generators based on Z/2Z-linear operations using multiplication by a suitable constant. Shortly after
high-dimensional xorshift* generators were introduced, Saito and Matsumoto suggested a different way to
eliminate linear artifacts based on addition in Z/2
32
Z, leading to the XSadd generator. Starting from the
observation that the lower bits of XSadd are very weak, as its reverse fails several statistical tests, we explore
variants of XSadd using 64-bit operations, and describe in detail xorshift128+, an extremely fast generator
that passes strong statistical tests using only three shifts, four xors and an addition.
Categories and Subject Descriptors: G.3 [PROBABILITY AND STATISTICS]: Random number gen-
eration; G.3 [PROBABILITY AND STATISTICS]: Experimental design
General Terms: Algorithms, Experimentation, Measurement
Additional Key Words and Phrases: Pseudorandom number generators
1. INTRODUCTION
xorshift generators are a simple class of pseudorandom number generators introduced
by Marsaglia [2003]. While it is known that such generators have some deficiencies [Pan-
neton and L’Ecuyer 2005], the author has shown recently that high-dimensional xorshift*
generators, which scramble the output of a xorshift using multiplication by a constant,
pass the strongest statistical tests of the TestU01 suite [L’Ecuyer and Simard 2007].
Shortly after the introduction of high-dimensional xorshift* generators, Saito and Mat-
sumoto [2014] proposed a different way to eliminate linear artifacts: instead of multiplying
the output of the underlying xorshift generator (based on 32-bit shifts) by a constant,
they add it (in Z/2
32
Z) with the previous output. Since the sum in Z/2
32
Z is not linear
over Z/2Z, the result should be free of linear artifacts.
Their generator XSadd has 128 bits of state and full period 2
128
−1. However, while XSadd
passes BigCrush, its reverse fails the LinearComp, MatrixRank, MaxOft and Permutation
test of BigCrush, which highlights a significant weakness in its lower bits.
In this paper, leveraging the theoretical and experimental data about xorshift gen-
erators contained in [Vigna 2014], we study xorshift+, a family of generators based on
the idea of XSadd, but using 64-bit operations. In particular, we propose a tightly coded
xorshift128+ generator that does not fail any test from the BigCrush suite of TestU01
(even reversed) and generates 64 pseudorandom bits in 1.06 ns on an Intel
R
Core
TM
i7-
4770 CPU @3.40GHz (Haswell). It is the fastest full-period generator we are aware of with
such empirical statistical properties.
2. xorshift GENERATORS
The basic idea of xorshift generators is that the state is modified by applying repeatedly
a shift and an exclusive-or (xor) operation. In this paper we consider 64-bit shifts and states
made of 2
n
bits, with n ≥ 7. We usually append n to the name of a family of generators
when we need to restrict the discussion to a specific state size.
In linear-algebra terms, if L is the 64 × 64 matrix on Z/2Z that effects a left shift of
one position on a binary row vector (i.e., L is all zeroes except for ones on the principal
subdiagonal) and if R is the right-shift matrix (the transpose of L), each left/right shift/xor
Author’s addresses: Sebastiano Vigna, Dipartimento di Informatica, Universit`a degli Studi di Milano, via
Comelico 39, 20135 Milano MI, Italy.
arXiv:1404.0390v3 [cs.DS] 23 May 2016