Crate urandom

Source
Expand description

Produce and consume randomness.

This crate provides utilities to generate random numbers, to convert them to useful types and distributions, and some randomness-related algorithms.

This library is inspired by the semi-official rand crate and an attempt to provide a better experience.

§Quick Start

To get you started quickly, the easiest and highest-level way to get a random value is to use urandom::new().next().

The Random struct provides a useful API on all Rng, while the distr module provide specific distributions on top of Rngs.

let mut rand = urandom::new();

// Generates a random boolean
if rand.coin_flip() {
	// Try printing a random unicode code point (probably a bad idea)!
	println!("char: {}", rand.next::<char>());
}

// Generates a float between 13.0 and 42.0
let y: f64 = rand.range(13.0..42.0);

// Shuffles the list of numbers
let mut numbers: Vec<i32> = (1..100).collect();
rand.shuffle(&mut numbers);

Re-exports§

pub use self::rng::Rng;
pub use self::distr::Distribution;

Modules§

distr
Generating random samples from probability distributions.
rng
Random number generators.

Structs§

Random
Rich interface for consuming random number generators.

Functions§

csprng
Creates a new cryptographically secure PRNG.
new
Creates a new instance of the default PRNG.
seeded
Creates a new instance of the default PRNG with the given seed.