Table of Contents
Fetching ...

Fast Gaussian Distributed Pseudorandom Number Generation in Java via the Ziggurat Algorithm

Vincent A. Cicirello

TL;DR

This work evaluates Gaussian variate generation via the ziggurat algorithm in Java, comparing a ported open-source implementation to Java 17's Gaussian methods (polar and McFarland's modified ziggurat). It finds that Java 17's modified ziggurat is faster where available, but the authors' original ziggurat remains advantageous for pre-Java 17 environments and for PRNGs that do not support the modified variant. The paper demonstrates a wrapper technique to leverage the modified ziggurat in some contexts and documents reproducible experiments, highlighting practical guidance for RNG choices across Java versions. Overall, it provides a detailed performance landscape and actionable recommendations for developers needing fast Gaussian RNG across Java runtimes, backed by an open-source implementation.

Abstract

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.

Fast Gaussian Distributed Pseudorandom Number Generation in Java via the Ziggurat Algorithm

TL;DR

This work evaluates Gaussian variate generation via the ziggurat algorithm in Java, comparing a ported open-source implementation to Java 17's Gaussian methods (polar and McFarland's modified ziggurat). It finds that Java 17's modified ziggurat is faster where available, but the authors' original ziggurat remains advantageous for pre-Java 17 environments and for PRNGs that do not support the modified variant. The paper demonstrates a wrapper technique to leverage the modified ziggurat in some contexts and documents reproducible experiments, highlighting practical guidance for RNG choices across Java versions. Overall, it provides a detailed performance landscape and actionable recommendations for developers needing fast Gaussian RNG across Java runtimes, backed by an open-source implementation.

Abstract

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.
Paper Structure (4 sections, 4 tables)

This paper contains 4 sections, 4 tables.