Over time, the scope of the project has grown, and Rand has moved from using a monolithic crate to using a "main" crate plus multiple single-purpose crates. For new functionality, one must consider where, and whether, it fits within the Rand project.
Small, focused crates may be used for a few reasons, but we aim not to maximally divide functionality into small crates. Valid reasons for using a separate crate for a feature are therefore:
- to allow a clear dependency hierarchy (
- to make the feature available in a stand-alone fashion (e.g.
- to remove little-used features with non-trivial amounts of code from widely
used crates (e.g.
rand_distrboth extracted functionality from
- to allow choice, without including large amounts of unused code for all
users, but also without producing an enormous number of new crates
(RNG family crates like
Traits, basics and UI
The main user interface to the Rand project remains the central
Goals for this crate are:
- ease of use
- expose commonly used functionality in a single place
- permit usage of additional randomness sources and distribution samplers
To allow better modularity, the core traits have been moved to the
crate. Goals of this crate are:
- expose the core traits with minimal dependencies
- provide common tools needed to implement various randomness sources
External random sources
The main (and usually only) external source of randomness is the Operating
System, interfaced via the
getrandom crate. This crate also supports usage of
RDRAND on a few
Support for other
no_std targets has been discussed but with little real
implementation effort. See
rand_jitter crate provides an implementation of a
CPU Jitter entropy harvester, and is only
included in Rand for historical reasons.
The Rand library includes several pseudo-random number generators, for the following reasons:
- to implement the
- to provide a few high-quality alternative generators
- historical usage
These are implemented within "family" crates, e.g.
We have received several requests to adopt new algorithms into the library; when evaluating such requests we must consider several things:
- purpose for inclusion within Rand
- whether the PRNG is cryptographically secure, and if so, how trustworthy such claims are
- statistical quality of output
- performance and features of the generator
- reception and third-party review of the algorithm
Distribution trait is provided by Rand, along with commonly-used
distributions (mostly linear ones).
Additional distributions are packaged within the
rand_distr crate, which
rand and re-exports all of its distributions.