A Rust library for sampling from various distributions
  • Rust 98.9%
  • Python 1.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-04-06 15:20:19 +02:00
benches Update rand 0.10 (#50) 2026-02-10 13:14:34 +00:00
distr_test Update rand 0.10 (#50) 2026-02-10 13:14:34 +00:00
fuzz Add fuzzer for distribution parameters (#53) 2026-03-19 14:30:04 +01:00
src Merge pull request #46 from mstoeckl/gamma-avoid-nan 2026-02-10 08:39:45 +00:00
tests Update rand dependency to latest rc 2026-02-07 12:21:58 -05:00
utils rand::distributions -> distr; split uniform module (#1470) 2024-07-23 14:14:11 +01:00
.gitignore Ignore temporary files associated with wasm_bindgen test 2019-03-04 08:50:01 +00:00
Cargo.toml chore: sync dependencies (monorepo) 2026-04-06 15:20:19 +02:00
clippy.toml Fix clippy::doc_markdown warnings. (#1474) 2024-07-20 09:56:27 +01:00
COPYRIGHT Fix directories (#3) 2025-02-05 17:29:11 +01:00
LICENSE-APACHE Fix directories (#3) 2025-02-05 17:29:11 +01:00
LICENSE-MIT Fix directories (#3) 2025-02-05 17:29:11 +01:00
README.md Remove links to rust-random.github.io/rand (#42) 2025-12-06 00:06:55 +01:00

rand_distr

Test Status Latest version Book API

Implements a full suite of random number distribution sampling routines.

This crate is a superset of the rand::distr module, including support for sampling from Beta, Binomial, Cauchy, ChiSquared, Dirichlet, Exponential, FisherF, Gamma, Geometric, Hypergeometric, InverseGaussian, LogNormal, Normal, Pareto, PERT, Poisson, StudentT, Triangular and Weibull distributions. Sampling from the unit ball, unit circle, unit disc and unit sphere surfaces is also supported.

It is worth mentioning the statrs crate which provides similar functionality along with various support functions, including PDF and CDF computation. In contrast, this rand_distr crate focuses on sampling from distributions.

Portability and libm

The floating point functions from num_traits and libm are used to support no_std environments and ensure reproducibility. If the floating point functions from std are preferred, which may provide better accuracy and performance but may produce different random values, the std_math feature can be enabled. (Note that any other crate depending on num-traits with the std feature (default-enabled) will have the same effect.)

Crate features

  • std (enabled by default): rand_distr implements the Error trait for its error types. Implies alloc and rand/std.
  • alloc (enabled by default): required for some distributions when not using std (in particular, Dirichlet and WeightedAliasIndex).
  • std_math: see above on portability and libm
  • serde: implement (de)seriaialization using serde

Old Issues and Pull Requests

  • All closed Issues and merged Pull requests from before 5.February.2025 (version 0.5.0) can be found in the rand repository where this crate used to be.

License

rand_distr is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT, and COPYRIGHT for details.