We report on experiments with the ziggurat algorithm for generating Gaussian distributed random numbers. The study utilizes our open source Java implementation that was introduced originally for Java 11 at a time when the Java API only provided the much slower polar method. Our Java implementation of the ziggurat algorithm is a port of the GNU Scientific Library's C implementation. Java 17 introduced a significant overhaul of pseudorandom number generation, including several modern pseudorandom number generators (PRNGs) as well as additional functionality, among which includes switching from the polar method to a modified ziggurat algorithm. In the experiments of this paper, we explore whether there is still a need for our implementation for Java 17+ applications. Our results show that Java 17's modified ziggurat is faster than our implementation for the PRNGs that support it. However, Java 17+ continues to use the polar method for the legacy PRNGs Random, SecureRandom, and ThreadLocalRandom. The linear congruential method of Java's Random class lacks the statistical properties required by Java's modified ziggurat implementation; and SecureRandom and ThreadLocalRandom unfortunately use the polar method as a side-effect of extending Random. Our implementation of the original ziggurat algorithm does not require the same statistical properties of the underlying PRNG as Java 17's optimized version, and can be used with any of these PRNGs, and is especially relevant where pre-Java 17 support is required.
翻译:我们报告了使用Ziggurat算法生成高斯分布随机数的实验研究。该研究采用我们最初为Java 11开发的开源Java实现——当时Java API仅提供速度慢得多的极坐标法。我们的Ziggurat算法Java实现移植自GNU科学库的C语言版本。Java 17对伪随机数生成进行了重大革新,引入了若干现代伪随机数生成器(PRNGs)及附加功能,其中包括从极坐标法切换到改进型Ziggurat算法。本文通过实验探讨在Java 17+应用中是否仍需要我们的实现。实验结果表明,对于支持改进型Ziggurat的PRNGs,Java 17的改进版本比我们的实现更快。然而,Java 17+在传统PRNGs(Random、SecureRandom和ThreadLocalRandom)中仍继续使用极坐标法:Java的Random类采用的线性同余法无法满足Java改进型Ziggurat实现所需的统计特性;而SecureRandom和ThreadLocalRandom因继承Random类而被迫沿用极坐标法。我们实现的原始Ziggurat算法对底层PRNG的统计特性要求低于Java 17优化版本,可兼容上述所有PRNGs,在需要支持Java 17前版本的环境中尤其具有应用价值。