Learning Pseudorandom Numbers with Transformers: Permuted Congruential Generators, Curricula, and Interpretability
Not on the map. Why?
Abstract (arXiv)
We study the ability of Transformer models to learn sequences generated by Permuted Congruential Generators (PCGs), a widely used family of pseudo-random number generators (PRNGs). PCGs introduce substantial additional difficulty over linear congruential generators (LCGs) by applying a series of bit-wise shifts, XORs, rotations and truncations to the hidden state. We show that Transformers can nevertheless successfully perform in-context prediction on unseen sequences from diverse PCG variants, in tasks that are beyond published classical attacks. In our experiments we scale moduli up to 222 using up to 50 million model parameters and datasets with up to 5 billion tokens. Surprisingly, we find even when the output is truncated to a single bit, it can be reliably predicted by the model. When multiple distinct PRNGs are presented together during training, the model can jointly learn them, identifying structures from different permutations. We demonstrate a scaling law with modulus m: the number of in-context sequence elements required for near-perfect prediction grows as √m. For larger moduli, optimization enters extended stagnation phases; in our experiments, learning moduli m ≥ 220 requires incorporating training data from smaller moduli, demonstrating a critical necessity for curriculum learning. Finally, we analyze embedding layers and uncover a novel clustering phenomenon: the top principal components spontaneously group the integer inputs into bitwise rotationally-invariant clusters, revealing how representations can transfer from smaller to larger moduli.
Key facts. No citing papers in the map yet (data through 14 Oct 2026). Builds on 17 of its 28 references that are in the map. First posted on arXiv 30 Oct 2025.
Builds on
17 of 28 references.
References · 17
- 2020Language Models are Few-Shot Learnerscited by 32,419
- 2020An Image is Worth 16x16 Words: Transformers for Image Recognition at Scalecited by 30,186
- 2021RoFormer: Enhanced Transformer with Rotary Position Embeddingcited by 4,703
- 2021An Explanation of In-context Learning as Implicit Bayesian Inferencecited by 938
- 2023Progress measures for grokking via mechanistic interpretabilitycited by 839
- 2022What Can Transformers Learn In-Context? A Case Study of Simple Function Classescited by 715
- 2022Grokking: Generalization Beyond Overfitting on Small Algorithmic Datasetscited by 629
- 2022Towards Understanding Grokking: An Effective Theory of Representation Learningcited by 230
- 2023The Clock and the Pizza: Two Stories in Mechanistic Explanation of Neural Networkscited by 156
- 2020When Do Curricula Work?cited by 106
- 2024Learning to grok: Emergence of in-context learning and skill composition in modular arithmetic taskscited by 40
- 2022SALSA: Attacking Lattice Cryptography with Transformerscited by 28
5 more
- 2023To grok or not to grok: Disentangling generalization and memorization on corrupted algorithmic datasetscited by 24
- 2024Emergent properties with repeated examplescited by 11
- 2025(How) Can Transformers Predict Pseudo-Random Numbers?cited by 6
- 2024Making Hard Problems Easier with Custom Data Distributions and Loss Regularization: A Case Study in Modular Arithmeticcited by 4
- 2025Pre-trained Large Language Models Learn Hidden Markov Models In-contextcited by 4
Built on by
Not cited yet.