16 releases

0.5.1 Feb 20, 2025
0.5.0-beta.2 Nov 30, 2024
0.5.0-alpha.3 Jul 31, 2024
0.5.0-alpha.1 Mar 18, 2024
0.2.1 Jun 28, 2019

#60 in Algorithms

Download history 440795/week @ 2024-11-01 459298/week @ 2024-11-08 469687/week @ 2024-11-15 372901/week @ 2024-11-22 362809/week @ 2024-11-29 461441/week @ 2024-12-06 440041/week @ 2024-12-13 194422/week @ 2024-12-20 183223/week @ 2024-12-27 409317/week @ 2025-01-03 493529/week @ 2025-01-10 409833/week @ 2025-01-17 429925/week @ 2025-01-24 473028/week @ 2025-01-31 660783/week @ 2025-02-07 276494/week @ 2025-02-14

1,918,568 downloads per month
Used in 2,870 crates (570 directly)

MIT/Apache

270KB
5K SLoC

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.

Dependencies

~1.7–7MB
~37K SLoC