Expand description
Random-number generators and samplers
§Quick Start
// rand::random() supports many common types:
println!("Uniform i8 sample: {}", match rand::random() {
0i8 => "zero",
i if i > 0 => "positive",
_ => "negative",
});
// Ranged sampling:
use std::f32::consts::PI;
println!("Angle: {} degrees", rand::random_range(-PI..PI));See also The Book: Quick Start.
Re-exports§
pub use rand_core;
Modules§
- distr
- Generating random samples from probability distributions
- prelude
- Convenience re-export of common members
- rngs
- Random number generators and adapters
- seq
- Sequence-related functionality
Structs§
- RngReader
std - Adapter to support
std::io::Readover aTryRng
Traits§
- Crypto
Rng - A marker trait for securely unpredictable infallible RNGs
- Fill
- Support filling a slice with random data
- Rng
- Trait for infallible random number generators
- RngExt
- User-level interface for RNGs
- Seedable
Rng - A random number generator that can be explicitly seeded.
- TryCrypto
Rng - A marker trait over
TryRngfor securely unpredictable RNGs - TryRng
- Base trait for random number generators and random data sources
Functions§
- fill
thread_rng - Fill any type implementing
Fillwith random data - make_
rng sys_rng - Construct and seed an RNG
- random
thread_rng - Generate a random value using the thread-local random number generator.
- random_
bool thread_rng - Return a bool with a probability
pof being true. - random_
iter thread_rng - Return an iterator over
random()variates - random_
range thread_rng - Generate a random value in the given range using the thread-local random number generator.
- random_
ratio thread_rng - Return a bool with a probability of
numerator/denominatorof being true. - rng
thread_rng - Access a fast, pre-initialized generator