237
Views
5
CrossRef citations to date
0
Altmetric
Original Articles

A modified ziggurat algorithm for generating exponentially and normally distributed pseudorandom numbers

Pages 1281-1294 | Received 10 Apr 2014, Accepted 05 Jun 2015, Published online: 24 Jun 2015
 

Abstract

The ziggurat algorithm is a very fast rejection sampling method for generating pseudorandom numbers (PRNs) from statistical distributions. In the algorithm, rectangular sampling domains are layered on top of each other (resembling a ziggurat) to encapsulate the desired probability density function. Random values within these layers are sampled and then returned if they lie beneath the graph of the probability density function. Here, we present an implementation where ziggurat layers reside completely beneath the probability density function, thereby eliminating the need for any rejection test within the ziggurat layers. In the new algorithm, small overhanging segments of probability density remain to the right of each ziggurat layer, which can be efficiently sampled with triangularly shaped sampling domains. Median runtimes of the new algorithm for exponential and normal variates is reduced to 58% and 53%, respectively (collective range: 41–93%). An accessible C library, along with extensions into Python and MATLAB/Octave are provided.

Acknowledgments

I would like to thank Anton Goloborodko, Christine Miller, Geoffrey Fudenberg, Maxim Imakaev, and Nezar Abdennur for helpful discussions and comments.

Disclosure statement

No potential conflict of interest was reported by the author.

Additional information

Funding

This work was supported by the National Cancer Institute under grant U54CA143874.

Log in via your institution

Log in to Taylor & Francis Online

PDF download + Online access

  • 48 hours access to article PDF & online version
  • Article PDF can be downloaded
  • Article PDF can be printed
USD 61.00 Add to cart

Issue Purchase

  • 30 days online access to complete issue
  • Article PDFs can be downloaded
  • Article PDFs can be printed
USD 1,209.00 Add to cart

* Local tax will be added as applicable

Related Research

People also read lists articles that other readers of this article have read.

Recommended articles lists articles that we recommend and is powered by our AI driven recommendation engine.

Cited by lists all citing articles based on Crossref citations.
Articles with the Crossref icon will open in a new tab.