Rand

Trait Rand 

Source
pub trait Rand: Sized {
    // Required method
    fn rand<R>(rng: &mut R) -> Self
       where R: Rng;
}
Expand description

A type that can be randomly generated using an Rng.

§Built-in Implementations

This crate implements Rand for various primitive types. Assuming the provided Rng is well-behaved, these implementations generate values with the following ranges and distributions:

  • Integers (i32, u32, isize, usize, etc.): Uniformly distributed over all values of the type.
  • char: Uniformly distributed over all Unicode scalar values, i.e. all code points in the range 0...0x10_FFFF, except for the range 0xD800...0xDFFF (the surrogate code points). This includes unassigned/reserved code points.
  • bool: Generates false or true, each with probability 0.5.
  • Floating point types (f32 and f64): Uniformly distributed in the half-open range [0, 1). (The Open01, Closed01, Exp1, and StandardNormal wrapper types produce floating point numbers with alternative ranges or distributions.)

The following aggregate types also implement Rand as long as their component types implement it:

  • Tuples and arrays: Each element of the tuple or array is generated independently, using its own Rand implementation.
  • Option<T>: Returns None with probability 0.5; otherwise generates a random T and returns Some(T).

Required Methods§

Source

fn rand<R>(rng: &mut R) -> Self
where R: Rng,

Generates a random instance of this type using the specified source of randomness.

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.

Implementations on Foreign Types§

Source§

impl Rand for bool

Source§

fn rand<R>(rng: &mut R) -> bool
where R: Rng,

Source§

impl Rand for char

Source§

fn rand<R>(rng: &mut R) -> char
where R: Rng,

Source§

impl Rand for f32

Source§

fn rand<R>(rng: &mut R) -> f32
where R: Rng,

Generate a floating point number in the half-open interval [0,1).

See Closed01 for the closed interval [0,1], and Open01 for the open interval (0,1).

Source§

impl Rand for f64

Source§

fn rand<R>(rng: &mut R) -> f64
where R: Rng,

Generate a floating point number in the half-open interval [0,1).

See Closed01 for the closed interval [0,1], and Open01 for the open interval (0,1).

Source§

impl Rand for i8

Source§

fn rand<R>(rng: &mut R) -> i8
where R: Rng,

Source§

impl Rand for i16

Source§

fn rand<R>(rng: &mut R) -> i16
where R: Rng,

Source§

impl Rand for i32

Source§

fn rand<R>(rng: &mut R) -> i32
where R: Rng,

Source§

impl Rand for i64

Source§

fn rand<R>(rng: &mut R) -> i64
where R: Rng,

Source§

impl Rand for isize

Source§

fn rand<R>(rng: &mut R) -> isize
where R: Rng,

Source§

impl Rand for u8

Source§

fn rand<R>(rng: &mut R) -> u8
where R: Rng,

Source§

impl Rand for u16

Source§

fn rand<R>(rng: &mut R) -> u16
where R: Rng,

Source§

impl Rand for u32

Source§

fn rand<R>(rng: &mut R) -> u32
where R: Rng,

Source§

impl Rand for u64

Source§

fn rand<R>(rng: &mut R) -> u64
where R: Rng,

Source§

impl Rand for ()

Source§

fn rand<R>(_: &mut R)
where R: Rng,

Source§

impl Rand for usize

Source§

fn rand<R>(rng: &mut R) -> usize
where R: Rng,

Source§

impl<A> Rand for (A,)
where A: Rand,

Source§

fn rand<R>(_rng: &mut R) -> (A,)
where R: Rng,

Source§

impl<A, B> Rand for (A, B)
where A: Rand, B: Rand,

Source§

fn rand<R>(_rng: &mut R) -> (A, B)
where R: Rng,

Source§

impl<A, B, C> Rand for (A, B, C)
where A: Rand, B: Rand, C: Rand,

Source§

fn rand<R>(_rng: &mut R) -> (A, B, C)
where R: Rng,

Source§

impl<A, B, C, D> Rand for (A, B, C, D)
where A: Rand, B: Rand, C: Rand, D: Rand,

Source§

fn rand<R>(_rng: &mut R) -> (A, B, C, D)
where R: Rng,

Source§

impl<A, B, C, D, E> Rand for (A, B, C, D, E)
where A: Rand, B: Rand, C: Rand, D: Rand, E: Rand,

Source§

fn rand<R>(_rng: &mut R) -> (A, B, C, D, E)
where R: Rng,

Source§

impl<A, B, C, D, E, F> Rand for (A, B, C, D, E, F)
where A: Rand, B: Rand, C: Rand, D: Rand, E: Rand, F: Rand,

Source§

fn rand<R>(_rng: &mut R) -> (A, B, C, D, E, F)
where R: Rng,

Source§

impl<A, B, C, D, E, F, G> Rand for (A, B, C, D, E, F, G)
where A: Rand, B: Rand, C: Rand, D: Rand, E: Rand, F: Rand, G: Rand,

Source§

fn rand<R>(_rng: &mut R) -> (A, B, C, D, E, F, G)
where R: Rng,

Source§

impl<A, B, C, D, E, F, G, H> Rand for (A, B, C, D, E, F, G, H)
where A: Rand, B: Rand, C: Rand, D: Rand, E: Rand, F: Rand, G: Rand, H: Rand,

Source§

impl<A, B, C, D, E, F, G, H, I> Rand for (A, B, C, D, E, F, G, H, I)
where A: Rand, B: Rand, C: Rand, D: Rand, E: Rand, F: Rand, G: Rand, H: Rand, I: Rand,

Source§

impl<A, B, C, D, E, F, G, H, I, J> Rand for (A, B, C, D, E, F, G, H, I, J)
where A: Rand, B: Rand, C: Rand, D: Rand, E: Rand, F: Rand, G: Rand, H: Rand, I: Rand, J: Rand,

Source§

impl<A, B, C, D, E, F, G, H, I, J, K> Rand for (A, B, C, D, E, F, G, H, I, J, K)
where A: Rand, B: Rand, C: Rand, D: Rand, E: Rand, F: Rand, G: Rand, H: Rand, I: Rand, J: Rand, K: Rand,

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L> Rand for (A, B, C, D, E, F, G, H, I, J, K, L)
where A: Rand, B: Rand, C: Rand, D: Rand, E: Rand, F: Rand, G: Rand, H: Rand, I: Rand, J: Rand, K: Rand, L: Rand,

Source§

impl<T> Rand for Option<T>
where T: Rand,

Source§

fn rand<R>(rng: &mut R) -> Option<T>
where R: Rng,

Source§

impl<T> Rand for [T; 0]

Source§

fn rand<R>(_rng: &mut R) -> [T; 0]
where R: Rng,

Source§

impl<T> Rand for [T; 1]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 1]
where R: Rng,

Source§

impl<T> Rand for [T; 2]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 2]
where R: Rng,

Source§

impl<T> Rand for [T; 3]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 3]
where R: Rng,

Source§

impl<T> Rand for [T; 4]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 4]
where R: Rng,

Source§

impl<T> Rand for [T; 5]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 5]
where R: Rng,

Source§

impl<T> Rand for [T; 6]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 6]
where R: Rng,

Source§

impl<T> Rand for [T; 7]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 7]
where R: Rng,

Source§

impl<T> Rand for [T; 8]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 8]
where R: Rng,

Source§

impl<T> Rand for [T; 9]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 9]
where R: Rng,

Source§

impl<T> Rand for [T; 10]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 10]
where R: Rng,

Source§

impl<T> Rand for [T; 11]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 11]
where R: Rng,

Source§

impl<T> Rand for [T; 12]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 12]
where R: Rng,

Source§

impl<T> Rand for [T; 13]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 13]
where R: Rng,

Source§

impl<T> Rand for [T; 14]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 14]
where R: Rng,

Source§

impl<T> Rand for [T; 15]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 15]
where R: Rng,

Source§

impl<T> Rand for [T; 16]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 16]
where R: Rng,

Source§

impl<T> Rand for [T; 17]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 17]
where R: Rng,

Source§

impl<T> Rand for [T; 18]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 18]
where R: Rng,

Source§

impl<T> Rand for [T; 19]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 19]
where R: Rng,

Source§

impl<T> Rand for [T; 20]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 20]
where R: Rng,

Source§

impl<T> Rand for [T; 21]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 21]
where R: Rng,

Source§

impl<T> Rand for [T; 22]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 22]
where R: Rng,

Source§

impl<T> Rand for [T; 23]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 23]
where R: Rng,

Source§

impl<T> Rand for [T; 24]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 24]
where R: Rng,

Source§

impl<T> Rand for [T; 25]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 25]
where R: Rng,

Source§

impl<T> Rand for [T; 26]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 26]
where R: Rng,

Source§

impl<T> Rand for [T; 27]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 27]
where R: Rng,

Source§

impl<T> Rand for [T; 28]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 28]
where R: Rng,

Source§

impl<T> Rand for [T; 29]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 29]
where R: Rng,

Source§

impl<T> Rand for [T; 30]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 30]
where R: Rng,

Source§

impl<T> Rand for [T; 31]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 31]
where R: Rng,

Source§

impl<T> Rand for [T; 32]
where T: Rand,

Source§

fn rand<R>(_rng: &mut R) -> [T; 32]
where R: Rng,

Implementors§