Abstract

We show that the short period of the uniform random number generator in the published implementation of Marsaglia and Tsang's Ziggurat method for generating random deviates can lead to poor distributions. Changing the uniform random number generator used in its implementation fixes this issue.

proposed the Ziggurat method for generating a random variable from a given decreasing probability density.This method is one of the fastest available for generating normal variates.We applied the chi-square (χ 2 ) goodness-of-fit test (Knuth (1997)) to check the distribution of random variables generated using an implementation available from Marsaglia and Tsang (2000).
The χ 2 test involves quantizing the horizontal axis of the probability density function (pdf) into k bins, determining the actual and expected number of samples appearing in each bin, and using the results to derive a single number that serves as an overall quality metric.Let t be the number of observations, p i be the probability that each observation falls into the category i and Y i be the number of observations that actually do fall into category i.The The Ziggurat method was used to generate 20 billion normal random variates, and the distribution tested using the χ 2 test based on 200 bins spaced uniformly over [−7, 7]. the polar method1 (Knuth (1997), Project (2004)) and (b) a modified implementation of the Ziggurat method which uses a different uniform random number generator (RNG).For a 95% level of confidence, the critical value for the χ 2 199 test is 233.Since the values obtained for the original implementation of the Ziggurat method are all well above this value, we conclude that the generated values are not normally distributed.The polar method and modified Ziggurat method give χ 2 199 statistics below the critical value.Figure 1 shows a plot of the χ 2 199 value versus the iteration number for a typical trial.As can be seen, the critical value of 233 is exceeded when the uniform random number generator repeats after approximately 2 32 (4 billion) iterations.
To summarize, the Ziggurat normal RNG available from (Marsaglia and Tsang (2000)) does not pass a χ 2 test for a normal distribution due to the short period of the SHR3 uniform RNG used in its implementation.A modified version which uses the KISS uniform RNG is presented which addresses this issue with a minor performance penalty.It would be prudent to test simulations with several different uniform RNGs (Marsaglia (1999), Knuth (1997)) to ensure consistent results.

Figure 1 :
Figure 1: Plot of the χ 2 199 value versus the iteration number for a typical trial.

Table 1 :
χ 2 199 values for 5 experiments involving the generation of 20 billion normally distributed random variates.Speed is in million random numbers per second.
The χ 2 199 statistics for five different trials with different initial seeds are shown in Table1.As a comparison, the same test was repeated using (a) the GNU Scientific Library's implementation of