hn.today

Reversing Factorio's RNG

gegell.github.io4 points1 comments
Screenshot of Reversing Factorio's RNG

This write-up analyzes how item and building quality randomness introduced in the Space-Age DLC for Factorio is actually produced by a deterministic pseudo-random number generator and demonstrates that the RNG can be reverse-engineered and predicted. It explains that the game uses the taus88 generator (an XOR combination of three linear-feedback shift registers, LFSRs) from Boost.Random, and that because items’ quality outcomes are derived from this PRNG, knowing the algorithm and internal state allows exact prediction of future "random" events. A note clarifies that Factorio 2.1 changes RNG usage and breaks the author’s in-game implementations, but the underlying RNG algorithm remains the same so the theoretical analysis still applies.

The analysis traces the discovery from a forum hint by a developer to concrete confirmation: the author reimplemented both variants in Python, used symbolic manipulation with sympy to verify bitwise equivalence, and observed compiler-driven constant-folding in the optimized code. The write-up then explains LFSR mathematics - bit-vector representation over F2, linear feedback via XOR, modeling by polynomials, the importance of primitive feedback polynomials for maximal cycle length (2^n−1), and why LFSRs are linear and therefore trivially breakable. From these specifics the conclusion follows that the RNG’s linear structure enables reconstructing internal state from outputs and thus deterministic prediction and exploitation of in-game random mechanics.

Read on gegell.github.io1 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Security

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.