13 releases

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.4.3 Jan 18, 2022
0.2.1 Jun 28, 2019

#934 in Algorithms

Download history 449925/week @ 2024-08-20 434631/week @ 2024-08-27 469278/week @ 2024-09-03 437601/week @ 2024-09-10 407727/week @ 2024-09-17 457645/week @ 2024-09-24 458328/week @ 2024-10-01 467721/week @ 2024-10-08 477603/week @ 2024-10-15 485460/week @ 2024-10-22 451905/week @ 2024-10-29 464042/week @ 2024-11-05 468046/week @ 2024-11-12 446907/week @ 2024-11-19 331306/week @ 2024-11-26 321151/week @ 2024-12-03

1,648,235 downloads per month
Used in 2,464 crates (524 directly)

MIT/Apache

620KB
11K SLoC

rand_distr

Test Status Latest version Book API 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

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.4–10MB
~108K SLoC