# Crate rand_distr

source · [−]## Expand description

Generating random samples from probability distributions.

### Re-exports

This crate is a super-set of the `rand::distributions`

module. See the
`rand::distributions`

module documentation for an overview of the core
`Distribution`

trait and implementations.

The following are re-exported:

- The
`Distribution`

trait and`DistIter`

helper type - The
`Standard`

,`Alphanumeric`

,`Uniform`

,`OpenClosed01`

,`Open01`

,`Bernoulli`

, and`WeightedIndex`

distributions

### Distributions

This crate provides the following probability distributions:

- Related to real-valued quantities that grow linearly
(e.g. errors, offsets):
`Normal`

distribution, and`StandardNormal`

as a primitive`SkewNormal`

distribution`Cauchy`

distribution

- Related to Bernoulli trials (yes/no events, with a given probability):
`Binomial`

distribution`Geometric`

distribution`Hypergeometric`

distribution

- Related to positive real-valued quantities that grow exponentially
(e.g. prices, incomes, populations):
`LogNormal`

distribution

- Related to the occurrence of independent events at a given rate:
- Gamma and derived distributions:
`Gamma`

distribution`ChiSquared`

distribution`StudentT`

distribution`FisherF`

distribution

- Triangular distribution:
`Beta`

distribution`Triangular`

distribution

- Multivariate probability distributions
`Dirichlet`

distribution`UnitSphere`

distribution`UnitBall`

distribution`UnitCircle`

distribution`UnitDisc`

distribution

- Alternative implementation for weighted index sampling
`WeightedAliasIndex`

distribution

- Misc. distributions
`InverseGaussian`

distribution`NormalInverseGaussian`

distribution

## Re-exports

`pub use weighted_alias::WeightedAliasIndex;`

`alloc`

`pub use num_traits;`

## Modules

A distribution uniformly sampling numbers within a given range.

weighted_alias

`alloc`

This module contains an implementation of alias method for sampling random
indices with probabilities proportional to a collection of weights.

## Structs

Sample a

`u8`

, uniformly distributed over ASCII letters and numbers:
a-z, A-Z and 0-9.The Bernoulli distribution.

The Beta distribution with shape parameters

`alpha`

and `beta`

.The binomial distribution

`Binomial(n, p)`

.The Cauchy distribution

`Cauchy(median, scale)`

.The chi-squared distribution

`χ²(k)`

, where `k`

is the degrees of
freedom.Dirichlet

`alloc`

The Dirichlet distribution

`Dirichlet(alpha)`

.An iterator that generates random values of

`T`

with distribution `D`

,
using `R`

as the source of randomness.The exponential distribution

`Exp(lambda)`

.Samples floating-point numbers according to the exponential distribution,
with rate parameter

`λ = 1`

. This is equivalent to `Exp::new(1.0)`

or
sampling with `-rng.gen::<f64>().ln()`

, but faster.The Fisher F distribution

`F(m, n)`

.Samples floating-point numbers according to the Fréchet distribution

The Gamma distribution

`Gamma(shape, scale)`

distribution.The geometric distribution

`Geometric(p)`

bounded to `[0, u64::MAX]`

.Samples floating-point numbers according to the Gumbel distribution

The hypergeometric distribution

`Hypergeometric(N, K, n)`

.The log-normal distribution

`ln N(mean, std_dev**2)`

.The normal distribution

`N(mean, std_dev**2)`

.A distribution to sample floating point numbers uniformly in the open
interval

`(0, 1)`

, i.e. not including either endpoint.A distribution to sample floating point numbers uniformly in the half-open
interval

`(0, 1]`

, i.e. including 1 but not 0.Samples floating-point numbers according to the Pareto distribution

The PERT distribution.

The Poisson distribution

`Poisson(lambda)`

.The skew normal distribution

`SN(location, scale, shape)`

.A generic random value distribution, implemented for many primitive types.
Usually generates values with a numerically uniform distribution, and with a
range appropriate to the type.

Samples integers according to the geometric distribution with success
probability

`p = 0.5`

. This is equivalent to `Geometeric::new(0.5)`

,
but faster.Samples floating-point numbers according to the normal distribution

`N(0, 1)`

(a.k.a. a standard normal, or Gaussian). This is equivalent to
`Normal::new(0.0, 1.0)`

but faster.The Student t distribution,

`t(nu)`

, where `nu`

is the degrees of
freedom.The triangular distribution.

Sample values uniformly between two bounds.

Samples uniformly from the unit ball (surface and interior) in three
dimensions.

Samples uniformly from the edge of the unit circle in two dimensions.

Samples uniformly from the unit disc in two dimensions.

Samples uniformly from the surface of the unit sphere in three dimensions.

Samples floating-point numbers according to the Weibull distribution

WeightedIndex

`alloc`

A distribution using weighted sampling of discrete items

Samples integers according to the zeta distribution.

Samples integers according to the Zipf distribution.

## Enums

Error type returned from

`Bernoulli::new`

.Error type returned from

`Beta::new`

.Error type returned from

`Binomial::new`

.Error type returned from

`Cauchy::new`

.Error type returned from

`ChiSquared::new`

and `StudentT::new`

.DirichletError

`alloc`

Error type returned from

`Dirchlet::new`

.Error type returned from

`Exp::new`

.Error type returned from

`FisherF::new`

.Error type returned from

`Frechet::new`

.Error type returned from

`Gamma::new`

.Error type returned from

`Geometric::new`

.Error type returned from

`Gumbel::new`

.Error type returned from

`Hypergeometric::new`

.Error type returned from

`InverseGaussian::new`

Error type returned from

`Normal::new`

and `LogNormal::new`

.Error type returned from

`NormalInverseGaussian::new`

Error type returned from

`Pareto::new`

.Error type returned from

`Poisson::new`

.Error type returned from

`SkewNormal::new`

.Error type returned from

`Triangular::new`

.Error type returned from

`Weibull::new`

.WeightedError

`alloc`

Error type returned from

`WeightedIndex::new`

.Error type returned from

`Zeta::new`

.Error type returned from

`Zipf::new`

.## Traits

Types (distributions) that can be used to create a random instance of

`T`

.