Trait Rand

Source
pub trait Rand: Sized {
Show 18 methods // Required methods fn from_seed(seed: u64) -> Self; fn rand_u32(&mut self) -> u32; // Provided methods fn rand_u8(&mut self) -> u8 { ... } fn rand_u16(&mut self) -> u16 { ... } fn rand_u64(&mut self) -> u64 { ... } fn rand_usize(&mut self) -> usize { ... } fn rand_bounded_u32(&mut self, m: u32) -> u32 { ... } fn rand_bounded_u64(&mut self, m: u64) -> u64 { ... } fn rand_bounded_usize(&mut self, m: usize) -> usize { ... } fn rand_range_u32(&mut self, a: u32, b: u32) -> u32 { ... } fn rand_range_u64(&mut self, a: u64, b: u64) -> u64 { ... } fn rand_range_i32(&mut self, a: i32, b: i32) -> i32 { ... } fn rand_range_i64(&mut self, a: i64, b: i64) -> i64 { ... } fn rand_f32(&mut self) -> f32 { ... } fn rand_f64(&mut self) -> f64 { ... } fn choice<'a, T>(&mut self, a: &'a [T]) -> &'a T { ... } fn shuffle<T>(&mut self, a: &mut [T]) { ... } fn fill(&mut self, a: &mut [u8]) { ... }
}
Expand description

Provided utilities.

This interface permits to hide the used engine:

fn rng_from_seed(seed: u64) -> impl Rand {
    Rng::from_seed(seed)
}

Required Methods§

Source

fn from_seed(seed: u64) -> Self

To obtain reproducible results. If feature std is enabled, from_time() may be used instead, to use system time as microseconds as a seed. Apply from_seed(random_seed()) to establish a faster local RNG from a global seed RNG.

Source

fn rand_u32(&mut self) -> u32

A sample from the uniform distribution on 0..=u32::MAX.

Provided Methods§

Source

fn rand_u8(&mut self) -> u8

A sample from the uniform distribution on 0..=u8::MAX.

Source

fn rand_u16(&mut self) -> u16

A sample from the uniform distribution on 0..=u16::MAX.

Source

fn rand_u64(&mut self) -> u64

A sample from the uniform distribution on 0..=u64::MAX.

Source

fn rand_usize(&mut self) -> usize

A sample from the uniform distribution on 0..=usize::MAX.

Source

fn rand_bounded_u32(&mut self, m: u32) -> u32

A sample from the uniform distribution on 0..m.

Source

fn rand_bounded_u64(&mut self, m: u64) -> u64

A sample from the uniform distribution on 0..m.

Source

fn rand_bounded_usize(&mut self, m: usize) -> usize

A sample from the uniform distribution on 0..m.

Source

fn rand_range_u32(&mut self, a: u32, b: u32) -> u32

A sample from the uniform distribution on a..b.

Source

fn rand_range_u64(&mut self, a: u64, b: u64) -> u64

A sample from the uniform distribution on a..b.

Source

fn rand_range_i32(&mut self, a: i32, b: i32) -> i32

A sample from the uniform distribution on a..b.

Source

fn rand_range_i64(&mut self, a: i64, b: i64) -> i64

A sample from the uniform distribution on a..b.

Source

fn rand_f32(&mut self) -> f32

A sample from the uniform distribution on the interval [0, 1).
⚠️ WARNING: Achieving uniform distribution of floats is complex and requires analysis yet to be accomplished.

Source

fn rand_f64(&mut self) -> f64

A sample from the uniform distribution on the interval [0, 1).
⚠️ WARNING: Achieving uniform distribution of floats is complex and requires analysis yet to be accomplished.

Source

fn choice<'a, T>(&mut self, a: &'a [T]) -> &'a T

A sample from the uniform distribution on the non-empty slice.

Source

fn shuffle<T>(&mut self, a: &mut [T])

Shuffle an array randomly. The method is called Fisher–Yates shuffle and has linear time complexity.

Source

fn fill(&mut self, a: &mut [u8])

Fill a buffer with random bytes.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Rand for Rng