Non-cryptographic PRNGs

Xorshift128

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

unverified Root API only Not cryptographic
Unverified tier.

Source found and wired, correctness not fully proven. Root API only. Reach it with NextSSL(root=True) in Python or the nextssl_root_* functions in C.

About Xorshift128

Xorshift128 is a non-cryptographic pseudorandom generator. It uses a 1–268,435,456-byte output and a 16-byte seed. Its registry entry cites xorshift128 (Marsaglia 2003), NOT cryptographically secure. NextSSL lists it in the unverified tier and exposes it through the root API only (NextSSL(root=True) in Python, nextssl_root_* in C).

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

Sizes

FieldBytesMeaning
out1 – 268,435,456Output
seed16Seed

Use it

from nextssl_demo import NextSSL

root = NextSSL(root=True)   # tier 'unverified' is reachable from the root API only
buf = root.call("rng_fill", "xorshift128", "seed=42", 32)[0]   # not for keys

Calls follow the NextSSL C ABI and its language bindings. Buffer sizes are validated against the sizes above.

Frequently asked questions

What is Xorshift128?

Xorshift128 is a PRNG in the Xorshift128 family. Xorshift generators, introduced by George Marsaglia in 2003, produce pseudorandom numbers using only xor and shift operations on a small state.

What are the Xorshift128 sizes?

In NextSSL, Xorshift128 uses: output 1 to 268,435,456 bytes.

Who designed Xorshift128 and when?

Xorshift128 belongs to the Xorshift128 family, first published in 2003 by George Marsaglia. Its origin: Marsaglia, Xorshift RNGs (Journal of Statistical Software, 2003).

Which standards define Xorshift128?

Xorshift128 is referenced by xorshift128 (Marsaglia 2003), NOT cryptographically secure.

Is Xorshift128 safe to use?

Xorshift128 is in the unverified tier. Source found and wired, correctness not fully proven. Root API only. It is only reachable through the root API (NextSSL(root=True) in Python, nextssl_root_* in C).