[Paper Review] Middle-Square Weyl Sequence RNG
This paper proposes a novel random number generator (RNG) that combines John von Neumann’s middle-square method with a Weyl sequence to overcome the classic 'zero mechanism' problem. By adding a Weyl sequence—generated via modular addition of an odd constant—to the square of the state, the method ensures a period of at least $2^{64}$, uniform output distribution, and efficient execution in just four machine instructions, passing rigorous statistical tests like BigCrush and PractRand.
In this article, we propose a new implementation of John von Neumann's middle-square random number generator (RNG). A Weyl sequence keeps the generator running through a long period.
Motivation & Objective
- To address the fundamental flaw in von Neumann’s middle-square RNG—its tendency to collapse into zero or short cycles—by introducing a Weyl sequence to maintain state diversity.
- To ensure long-period, uniform random number generation using only 64-bit arithmetic and minimal computational overhead.
- To design a cryptographically suitable RNG that is both efficient and statistically robust, suitable for high-performance and parallel computing environments.
- To achieve statistical quality comparable to the Mersenne Twister while maintaining simplicity and speed through a compact, inline implementation.
Proposed method
- The RNG uses a 64-bit state variable `x` initialized to a non-zero value, and a separate 64-bit Weyl sequence state `w` initialized to zero.
- In each iteration, `x` is squared (mod $2^{64}$), then the Weyl sequence value `w` is updated via `w += s` where `s` is an odd constant (e.g., 0xb5ad4eceda1ce2a9).
- The middle 32 bits of the 64-bit result are extracted via a right rotate (circular shift) operation: `return (x >> 32) | (x << 32);`, effectively selecting the upper 32 bits after rotation.
- The Weyl sequence is mathematically proven to be periodic with period $2^{64}$ and contains no repeated values in the first $2^{64}$ elements due to the oddness of `s`, ensuring state diversity.
- The order of operations—squaring first, then adding the Weyl term—ensures uniform output distribution, as proven by Theorem C, which establishes that the sum of a non-uniform but random-like `x²` and a uniform Weyl sequence `w` yields a uniform output.
Experimental results
Research questions
- RQ1Can the middle-square method be made to avoid the 'zero mechanism' and long cycles by integrating a Weyl sequence?
- RQ2Does the addition of a Weyl sequence to the square of the state ensure a period of at least $2^{64}$?
- RQ3Is the output distribution of the modified middle-square RNG statistically uniform, especially when the input to the square is not uniformly distributed?
- RQ4Can this RNG achieve statistical quality comparable to established generators like the Mersenne Twister while remaining compact and efficient?
- RQ5Is the resulting RNG cryptographically suitable, given its long period and statistical robustness?
Key findings
- The Weyl sequence, generated by `w += s` with odd `s`, produces a period of exactly $2^{64}$, with all values in the range [0, $2^{64}-1$] appearing exactly once before repeating.
- The middle-square RNG with Weyl sequence addition has a minimum period of $2^{64}$ for the state `x`, as proven by Theorem B, which shows that equal `x` values cannot lead to repeated cycles due to distinct Weyl values.
- The output distribution is uniform, as shown in Theorem C: the sum of a non-uniform `x²` and a uniform Weyl sequence `w` results in a uniform output stream.
- The RNG compiles to only four machine instructions (imulq, iaddq, iaddq, rorq), enabling efficient inline use and high performance in tight loops.
- The generator passed the BigCrush and PractRand statistical test suites on the first attempt, confirming its statistical quality.
- The design is cryptographically suitable, as confirmed by arXiv’s classification in the Cryptography and Security section, and is robust across compilers due to careful C standard compliance.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.