Xorshift128
Marsaglia's minimal xor-and-shift generator, ancestor of xoshiro
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–2003Xorshift128 published by George Marsaglia
How it works
- Take t = x, then t ^= t << 11 and t ^= t >> 8.
- Shift the state: x = y, y = z, z = w.
- Set w = w ^ (w >> 19) ^ t.
- 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
Sizes
| Field | Bytes | Meaning |
|---|---|---|
| out | 1 – 268,435,456 | Output |
| seed | 16 | Seed |
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
nextssl_root_rng_fill("xorshift128", "seed=42", 32, out);
// prng is a root-only kind: use the C ABI (nextssl_root_*)
// or the Prng trait in nextssl-core/src/traits.rs
Calls follow the NextSSL C ABI and its language bindings. Buffer sizes are validated against the sizes above.
Similar names
Looking for something else?More non-cryptographic prngs
All 26Frequently 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).