Abstract
The Ziggurat and Monty Python methods are widely used, elegant algorithms designed to transform uniform random variables into other common distributions, such as normal or exponential. While these methods are mathematically sound, this paper identifies significant design flaws in the uniform pseudo-random number generators (PRNGs) used in their original published implementations. These flaws lead to non-uniformity and correlations that can invalidate stochastic simulations. Furthermore, we analyze the implementation of Matlab's randn (circa 2006), revealing similar issues with consecutive output correlations and linear initialization weaknesses.
Introduction
In scientific computing, the generation of high-quality random numbers is foundational. Most systems generate a uniform sequence (numbers between 0 and 1) and then apply a transformation to reach a target distribution. The Ziggurat method is a popular choice for generating normal distributions due to its speed. However, even a perfect transformation relies on the underlying uniform generator being truly independent and uniformly distributed. This paper exposes a "theory vs. practice" gap where the specific PRNGs recommended in the original Ziggurat and Monty Python papers fail basic statistical requirements.
Analysis of Implementation Flaws
The study performs a rigorous statistical analysis of three specific implementations: Marsaglia and Tsang’s SHR3 (shift-register) generator, the Monty Python method’s MWC (multiply-with-carry) generator, and the hybrid generator used in older versions of Matlab’s randn.
The Contractive Mapping Trap
A primary finding involves the SHR3 generator, which utilizes an output function of the form $x + Tx$. Analysis reveals that this mapping is not one-to-one; it is contractive. Specifically, the function can only produce approximately 64% of all possible 32-bit values.
As shown in the data above, over 1.5 billion possible 32-bit outputs have zero "sources" (pre-images), meaning they can never be generated by the algorithm. Conversely, some values have multiple pre-images, making them significantly more likely to appear. This "lumpy" distribution violates the assumption of first-order uniformity required for the Ziggurat transformation to function correctly.
Key Results and Statistical Failures
The paper utilizes $\chi^2$ (chi-squared) tests to quantify deviations from the theoretical ideal. For the SHR3 and KISS (which incorporates SHR3) generators, the deviation becomes statistically significant after roughly $2^{30}$ samples—a relatively small volume for modern high-performance computing tasks.
Matlab randn and Seeding Bias
Beyond simple uniformity, the paper identifies issues with second-order uniformity (independence between consecutive pairs). In older versions of Matlab’s randn, consecutive outputs were found to be highly correlated because the transformation used to combine its internal registers was also contractive.
Furthermore, the initialization process for these generators was often too simple. Using linear seeding (e.g., initializing parallel processors with seeds $i$ and $i+1$) could lead to different simulation streams sharing the same low-order bits. This lack of "seed sensitivity" means that supposedly independent simulation runs might actually produce mathematically dependent results, biasing the final outcome of stochastic experiments.
Conclusion
These findings serve as a critical reminder that the statistical soundness of a simulation is only as good as its underlying PRNG. The flaws identified in the Ziggurat and Monty Python implementations were not in the algorithms themselves, but in the choice of uniform generators and their initialization. To ensure robust results, modern scientific software should utilize generators with larger state spaces (e.g., 128-bit states for 32-bit outputs) and non-linear initialization functions to ensure that similar seeds produce truly divergent sequences.
Summary updated