8 releases

new 0.5.0-alpha.1 Mar 18, 2024
0.4.3 Jan 18, 2022
0.4.2 Sep 18, 2021
0.4.1 Jun 15, 2021
0.2.1 Jun 28, 2019

#798 in Algorithms

Download history 175491/week @ 2023-11-28 163668/week @ 2023-12-05 164891/week @ 2023-12-12 132939/week @ 2023-12-19 79326/week @ 2023-12-26 151288/week @ 2024-01-02 167313/week @ 2024-01-09 181524/week @ 2024-01-16 175169/week @ 2024-01-23 183192/week @ 2024-01-30 211041/week @ 2024-02-06 211797/week @ 2024-02-13 223301/week @ 2024-02-20 240195/week @ 2024-02-27 232960/week @ 2024-03-05 60210/week @ 2024-03-12

793,597 downloads per month
Used in 1,649 crates (427 directly)

MIT/Apache

570KB
10K SLoC

rand_distr

Test Status Latest version Book API API Minimum rustc version

Implements a full suite of random number distribution sampling routines.

This crate is a superset of the rand::distributions 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.

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
  • serde1: implement (de)seriaialization using serde

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.

Dependencies

~1.2–1.7MB
~29K SLoC