# Ziggurats.jl -- High performance non-uniform random number generators for user defined distributions

**URL:** https://discourse.julialang.org/t/ziggurats-jl-high-performance-non-uniform-random-number-generators-for-user-defined-distributions/130352
**Category:** Package Announcements
**Created:** [June 30, 2025, 10:56pm UTC](https://discourse.julialang.org/t/ziggurats-jl-high-performance-non-uniform-random-number-generators-for-user-defined-distributions/130352 "2025-06-30T22:56:59Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![npbarnes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/npbarnes/32/217905_2.png) [@npbarnes](https://discourse.julialang.org/u/npbarnes)
#### Post date: [June 30, 2025, 10:56pm UTC](https://discourse.julialang.org/t/ziggurats-jl-high-performance-non-uniform-random-number-generators-for-user-defined-distributions/130352/1 "2025-06-30T22:56:59Z")

</div>

Announcing the recently registered [`Ziggurats.jl`](https://github.com/npbarnes/Ziggurats.jl). Make very high performance random number generators for whatever distributions you like! (with some modest limitations)

[The ziggurat algorithm](https://en.wikipedia.org/wiki/Ziggurat_algorithm) uses a carefully constructed table of precomputed values to sample random numbers distributed according to a PDF with very high efficiency. It is widely used for high performance generation of normally distributed and exponentially distributed random numbers, including in Julia’s own `Random.jl`. The new package, [`Ziggurats.jl`](https://github.com/npbarnes/Ziggurats.jl), automates the process of constructing the ziggurat tables so you can get the same high performance sampling from a very wide variety of distributions. The main requirements are that the PDF must be univariate, piecewise monotonic, and must not diverge to infinite density. Even discontinuous functions should work.

### Example:

```julia-repl
julia> using Ziggurats, Plots, BenchmarkTools
julia> z = ziggurat(x->10 - x + sin(x), (0, 9.7));
julia> histogram(rand(z, 10^5))

```

 ![plot_1](https://global.discourse-cdn.com/julialang/original/3X/9/9/99d5a6dae19d67c31bd233bcfcebd0f5b24637e4.png)

```julia-auto
julia> @btime rand($z)
  3.920 ns (0 allocations: 0 bytes)

```

Check out the README on GitHub for more information: [`Ziggurats.jl`](https://github.com/npbarnes/Ziggurats.jl)

---

<div class="post-metadata">

### Author: ![npbarnes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/npbarnes/32/217905_2.png) [@npbarnes](https://discourse.julialang.org/u/npbarnes)
#### Post date: [January 28, 2026, 9:16pm UTC](https://discourse.julialang.org/t/ziggurats-jl-high-performance-non-uniform-random-number-generators-for-user-defined-distributions/130352/2 "2026-01-28T21:16:18Z")

</div>

Ziggurats.jl v0.2.0 is out now. It’s more robust, and faster than ever!

There have been a lot of bug fixes, mainly making it much more robust against issues caused by floating point round off and type instabilities.

Performance is improved for batch sampling using `rand(z, dims)` or `rand!(a, z)`. These methods should be preferred over repeated calls to `rand(z)`. In addition, a specialized/optimized sampler is now available for distributions that are symmetric and unimodal (bell-shaped); use the `BellZiggurat` constructor to get the best possible performance on this special class of distributions.

The package has all the features I want for a v1.0 release. The to-do list for v1.0 is mostly documentation, systematic benchmarking, and testing (the test suite is decent already, but I want it to be very thorough).

I’m interested to hear if anyone is using it, or considering using it? I originally had the idea while working on seeding particle-based plasma physics simulations, but obviously there’s a wide variety of possible applications. Tell me about yours.
