Expand description
Extension functionality for the fastrand
crate.
This crate contains code that may be of some use to users of fastrand
. Code contained in
this crate is not included in fastrand
due to either the niche not being large enough to
justify the new functionality or for semver concerns.
§Usage
Various functions are exposed in this crate as top-level functions. These manipulate the global
thread-local RNG and can be used without any local state. Note that these require the "std"
default feature to be enabled.
use fastrand_contrib::f32_range;
let x = f32_range(1.5..3.0);
assert!(x >= 1.5 && x < 3.0);
To extend fastrand::Rng
, import the RngExt
trait.
use fastrand_contrib::RngExt;
Now, all new methods are available on fastrand::Rng
.
use fastrand::Rng;
use fastrand_contrib::RngExt;
let mut rng = Rng::with_seed(0x1234);
let x = rng.f32_range(1.5..3.0);
assert!(x >= 1.5 && x < 3.0);
§Features
std
(enabled by default): Enables thestd
library. Freestanding functions only work with this feature enabled. Also enables thefastrand/std
feature.libm
: Useslibm
dependency for math functions inno_std
environment.
Note that some functions are not available in no_std
context if libm
feature is not enabled.
Re-exports§
pub use fastrand;
Structs§
- Rng
- A random number generator.
Traits§
- RngExt
- Extra methods for
fastrand::Rng
.
Functions§
- f32_
normal - Generate a 32-bit floating point number in the normal distribution with mean mu and standard deviation sigma.
- f32_
normal_ approx - Generate a 32-bit floating point number in the normal distribution with mean mu and standard deviation sigma using an approximation algorithm.
- f32_
range - Generate a 32-bit floating point number in the specified range.
- f64_
normal - Generate a 64-bit floating point number in the normal distribution with mean mu and standard deviation sigma.
- f64_
normal_ approx - Generate a 64-bit floating point number in the normal distribution with mean mu and standard deviation sigma using an approximation algorithm.
- f64_
range - Generate a 64-bit floating point number in the specified range.