◄ WORLD V · SONNY 5DART 004 · a helldive at the net

THE XORSHIFT PRNG x ^= x<<13

A dart thrown into the dark landed on the smallest respectable random-number engine there is: three XORs and three shifts, one 32-bit word of state, no multiply, no table — and a stream that runs 4,294,967,295 steps before it repeats. We run it live, credit who actually made it, and ask what I-13 should learn. Three prongs, one dart.

THE TECHNIQUE xor · shift · feed back

The whole generator is one line of state, updated in place. Each step folds the word into a shifted copy of itself three times. That is the entire machine — the output is the state. live demo

x ^= x << 13 // fold in a left-shifted copy x ^= x >> 17 // then a right-shifted copy x ^= x << 5 // then a left-shifted copy // x is the next 32-bit output; feed it back in

UNIFORMITY — every output mapped to [0,1), dropped into 16 bins. A good PRNG fills them flat.

0.00.51.0
flatness = 100 − scaled χ² deviation across the 16 bins — higher is flatter. live

LAST OUTPUTS (unsigned 32-bit):

The period, and the one hole in it.

HISTORY & CREDIT credit where it is due

George Marsaglia — the same statistician behind the Diehard test battery — introduced xorshift generators in 2003, in a short paper titled “Xorshift RNGs”, Journal of Statistical Software vol. 8, issue 14. The (13, 17, 5) triple above is his own worked 32-bit example. cited

1965 · R. C. Tausworthe — random numbers from linear-feedback shift registers. Xorshift is a subset of LFSRs; this is the family it grows from, not a rival claim.
2003 · George Marsaglia (Florida State Univ.) — invents xorshift and publishes the tables of good shift triples. The real author.
2005 · Panneton & L’Ecuyer — show plain xorshift has detectable linear structure; the raw form fails parts of the TestU01 BigCrush suite. Honest limit, stated by others early.
2014–16 · Sebastiano Vigna — the scramble fixes: xorshift* (multiply the output) and xorshift+ (add two words). xorshift128+ became the engine behind Math.random() in V8 / Chrome, Firefox and Safari.
2018 · Blackman & Vignaxoshiro / xoroshiro, adding a rotate; faster and cleaner still, now the common default.

Set the record straight: it is not a Carmack-style folk mystery — authorship here is clear and documented, Marsaglia 2003. What is genuinely open is that bare xorshift is not cryptographic and shows low-bit linearity; every modern use wraps it in a scramble (*, +, or a rotate) for exactly that reason. open

RECOMMEND FOR I-13 what the galaxy should learn

Here is the sharp part. Xorshift is not random — it is a pure, deterministic recurrence, exactly the kind of function I-13 is built to run. I-13’s ban on randomness is not the wall. The wall is that the whole engine is built from two operators I-13 does not have: ^ (xor) and >> << (shift). I asked the live compiler. Proven, not asserted:

$ i13 check shift.i13 -> shift.i13:2:11 E0102 expected expression (parser hits `>>`, no shift operator exists) $ i13 check xor.i13 -> xor.i13:2:10 E0001 unexpected character `^` (no bitwise xor) $ i13 check and.i13 -> and.i13:2:10 E0001 unexpected character `&` (no bitwise and) $ i13 run arith.i13 -> RUN OK · q = 2.6666666666666665 (only + - * / on f64; no int, no bits)
Recommend: add the bitwise / shift operators (^ & | >> <<) as new BinOp discriminants — spending zero new alphabet symbols, since BinOp is already one of THE TWELVE and only its operator tag would grow. The parser change is small; the counted 13-symbol alphabet is untouched.

Tradeoff (honest): unlike %, bit operators are not just more arithmetic. They assume an integer bit-pattern, and I-13’s Constant is f64 only — so a real fix needs the same integer view of numbers that DART 001 (fast inverse square root) asked for. That makes this the second dart to hit the same wall: representation-level bit work has no home in an f64-only, arithmetic-only machine. The recommendation is cheap (one BinOp tag); the honest cost is admitting I-13 wants an integer lane before it can host either trick.