https://github.com/jonhoo/rust-zipf
Rust implementation of a fast, bounded, Zipf-distributed random number generator
https://github.com/jonhoo/rust-zipf
random-number-distributions random-number-generators rust
Last synced: 9 months ago
JSON representation
Rust implementation of a fast, bounded, Zipf-distributed random number generator
- Host: GitHub
- URL: https://github.com/jonhoo/rust-zipf
- Owner: jonhoo
- License: apache-2.0
- Created: 2017-01-22T21:19:36.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-12-31T10:01:21.000Z (over 1 year ago)
- Last Synced: 2025-02-02T17:11:32.288Z (over 1 year ago)
- Topics: random-number-distributions, random-number-generators, rust
- Language: Rust
- Size: 120 KB
- Stars: 33
- Watchers: 3
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
> [!CAUTION]
> This crate is deprecated. Prefer
> [`rand_distr::Zipf`](https://docs.rs/rand_distr/latest/rand_distr/struct.Zipf.html).
---
# rust-zipf
[](https://crates.io/crates/zipf)
[](https://docs.rs/zipf/)
[](https://codecov.io/gh/jonhoo/rust-zipf)
[](https://deps.rs/repo/github/jonhoo/rust-zipf)
Rust implementation of a fast, discrete, bounded,
[Zipf-distributed](https://en.wikipedia.org/wiki/Zipf's_law) random
number generator. Compared to the implementation provided by
[`randomkit`](https://github.com/stygstra/rust-randomkit) (which binds
to NumPy's fork of RandomKit), this crate is approximately twice as
fast:
```console
$ cargo +nightly bench
test tests::bench_randomkit ... bench: 339 ns/iter (+/- 18)
test tests::bench_us ... bench: 68 ns/iter (+/- 1)
test tests::bench_threadrng ... bench: 11 ns/iter (+/- 0)
```
It is also both driven by, and provides, a [Rust random number
generator](https://doc.rust-lang.org/rand/rand/trait.Rng.html).
This implementation is effectively a direct port of Apache Common's
[RejectionInversionZipfSampler](https://github.com/apache/commons-rng/blob/6a1b0c16090912e8fc5de2c1fb5bd8490ac14699/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/RejectionInversionZipfSampler.java),
written in Java. It is based on the method described by Wolfgang Hörmann and Gerhard Derflinger
in [*Rejection-inversion to generate variates from monotone discrete
distributions*](https://dl.acm.org/citation.cfm?id=235029) from *ACM Transactions on Modeling
and Computer Simulation (TOMACS) 6.3 (1996)*.