Skip to main content

Crate rand

Crate rand 

Source
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§

RngReaderstd
Adapter to support std::io::Read over a TryRng

Traits§

CryptoRng
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
SeedableRng
A random number generator that can be explicitly seeded.
TryCryptoRng
A marker trait over TryRng for securely unpredictable RNGs
TryRng
Base trait for random number generators and random data sources

Functions§

fillthread_rng
Fill any type implementing Fill with random data
make_rngsys_rng
Construct and seed an RNG
randomthread_rng
Generate a random value using the thread-local random number generator.
random_boolthread_rng
Return a bool with a probability p of being true.
random_iterthread_rng
Return an iterator over random() variates
random_rangethread_rng
Generate a random value in the given range using the thread-local random number generator.
random_ratiothread_rng
Return a bool with a probability of numerator/denominator of being true.
rngthread_rng
Access a fast, pre-initialized generator