PRNG family

Xorshift128

Marsaglia's minimal xor-and-shift generator, ancestor of xoshiro

unverified 1 variant Marsaglia, Xorshift RNGs (Journal of Statistical Software, 2003)

Overview

Xorshift generators, introduced by George Marsaglia in 2003, produce pseudorandom numbers using only xor and shift operations on a small state. They are extremely fast but have known statistical weaknesses and are not cryptographic.

Xorshift128 keeps four 32-bit words. Each step takes the oldest word, applies a left shift xor and a right shift xor, combines it with the newest word and its right shift, and appends the result as the new state word and the output. The period is 2^128 - 1 for any nonzero seed. It was one of the first generators to show that very simple operations can produce long periods.

Because the output is a linear function of the state over GF(2), xorshift fails tests that detect linearity, such as the binary matrix rank and linear complexity tests in TestU01's BigCrush. The later xorshift*, xoroshiro and xoshiro families add nonlinear scramblers to fix this. One variant is present: xorshift128. It remains useful only where code size matters most and statistical quality is secondary.

History

2003–2003
  1. Xorshift128 published by George Marsaglia

How it works

  1. Take t = x, then t ^= t << 11 and t ^= t >> 8.
  2. Shift the state: x = y, y = z, z = w.
  3. Set w = w ^ (w >> 19) ^ t.
  4. Return w.

Security notes

Not cryptographically secure: the state is linear and is exposed directly in its outputs, so four consecutive outputs reveal the whole state. It also fails some statistical tests; prefer xoshiro or PCG for non-security uses.

Typical uses

Very lightweight randomness in embedded or graphics codeTeaching generator designReproducing legacy sequences

Variants in NextSSL

1
AlgorithmTierSizes (bytes)StandardsAPI
Xorshift128
xorshift128
unverified out 1–268435456 · seed 16 xorshift128 (Marsaglia 2003), NOT cryptographically secure root

Frequently asked questions

Which Xorshift128 variants does NextSSL include?

NextSSL registers 1 Xorshift128 variant: xorshift128.