Struct rand::distributions::Uniform [] [src]

pub struct Uniform;

A generic random value distribution. Generates values for various types with numerically uniform distribution.

For floating-point numbers, this generates values from the open range (0, 1) (i.e. excluding 0.0 and 1.0).

Built-in Implementations

This crate implements the distribution Uniform 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 open range (0, 1).

The following aggregate types also implement the distribution Uniform as long as their component types implement it:

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

Example

use rand::{NewRng, SmallRng, Rng};
use rand::distributions::Uniform;

let val: f32 = SmallRng::new().sample(Uniform);
println!("f32 from [0,1): {}", val);

With dynamic dispatch (type erasure of Rng):

use rand::{thread_rng, Rng, RngCore};
use rand::distributions::Uniform;

let mut rng = thread_rng();
let mut erased_rng: &mut RngCore = &mut rng;
let val: f32 = erased_rng.sample(Uniform);
println!("f32 from [0,1): {}", val);

Trait Implementations

impl Distribution<f32> for Uniform
[src]

[src]

Generate a floating point number in the open interval (0, 1) (not including either endpoint) with a uniform distribution.

Example

use rand::{NewRng, SmallRng, Rng};
use rand::distributions::Uniform;

let val: f32 = SmallRng::new().sample(Uniform);
println!("f32 from (0,1): {}", val);

impl Distribution<f64> for Uniform
[src]

[src]

Generate a floating point number in the open interval (0, 1) (not including either endpoint) with a uniform distribution.

Example

use rand::{NewRng, SmallRng, Rng};
use rand::distributions::Uniform;

let val: f32 = SmallRng::new().sample(Uniform);
println!("f32 from (0,1): {}", val);

impl Distribution<isize> for Uniform
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl Distribution<i8> for Uniform
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl Distribution<i16> for Uniform
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl Distribution<i32> for Uniform
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl Distribution<i64> for Uniform
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl Distribution<usize> for Uniform
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl Distribution<u8> for Uniform
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl Distribution<u16> for Uniform
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl Distribution<u32> for Uniform
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl Distribution<u64> for Uniform
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl Distribution<char> for Uniform
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl Distribution<bool> for Uniform
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl Distribution<()> for Uniform
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<A> Distribution<(A,)> for Uniform where
    Uniform: Distribution<A>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<A, B> Distribution<(A, B)> for Uniform where
    Uniform: Distribution<A>,
    Uniform: Distribution<B>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<A, B, C> Distribution<(A, B, C)> for Uniform where
    Uniform: Distribution<A>,
    Uniform: Distribution<B>,
    Uniform: Distribution<C>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<A, B, C, D> Distribution<(A, B, C, D)> for Uniform where
    Uniform: Distribution<A>,
    Uniform: Distribution<B>,
    Uniform: Distribution<C>,
    Uniform: Distribution<D>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<A, B, C, D, E> Distribution<(A, B, C, D, E)> for Uniform where
    Uniform: Distribution<A>,
    Uniform: Distribution<B>,
    Uniform: Distribution<C>,
    Uniform: Distribution<D>,
    Uniform: Distribution<E>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<A, B, C, D, E, F> Distribution<(A, B, C, D, E, F)> for Uniform where
    Uniform: Distribution<A>,
    Uniform: Distribution<B>,
    Uniform: Distribution<C>,
    Uniform: Distribution<D>,
    Uniform: Distribution<E>,
    Uniform: Distribution<F>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<A, B, C, D, E, F, G> Distribution<(A, B, C, D, E, F, G)> for Uniform where
    Uniform: Distribution<A>,
    Uniform: Distribution<B>,
    Uniform: Distribution<C>,
    Uniform: Distribution<D>,
    Uniform: Distribution<E>,
    Uniform: Distribution<F>,
    Uniform: Distribution<G>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<A, B, C, D, E, F, G, H> Distribution<(A, B, C, D, E, F, G, H)> for Uniform where
    Uniform: Distribution<A>,
    Uniform: Distribution<B>,
    Uniform: Distribution<C>,
    Uniform: Distribution<D>,
    Uniform: Distribution<E>,
    Uniform: Distribution<F>,
    Uniform: Distribution<G>,
    Uniform: Distribution<H>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<A, B, C, D, E, F, G, H, I> Distribution<(A, B, C, D, E, F, G, H, I)> for Uniform where
    Uniform: Distribution<A>,
    Uniform: Distribution<B>,
    Uniform: Distribution<C>,
    Uniform: Distribution<D>,
    Uniform: Distribution<E>,
    Uniform: Distribution<F>,
    Uniform: Distribution<G>,
    Uniform: Distribution<H>,
    Uniform: Distribution<I>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<A, B, C, D, E, F, G, H, I, J> Distribution<(A, B, C, D, E, F, G, H, I, J)> for Uniform where
    Uniform: Distribution<A>,
    Uniform: Distribution<B>,
    Uniform: Distribution<C>,
    Uniform: Distribution<D>,
    Uniform: Distribution<E>,
    Uniform: Distribution<F>,
    Uniform: Distribution<G>,
    Uniform: Distribution<H>,
    Uniform: Distribution<I>,
    Uniform: Distribution<J>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<A, B, C, D, E, F, G, H, I, J, K> Distribution<(A, B, C, D, E, F, G, H, I, J, K)> for Uniform where
    Uniform: Distribution<A>,
    Uniform: Distribution<B>,
    Uniform: Distribution<C>,
    Uniform: Distribution<D>,
    Uniform: Distribution<E>,
    Uniform: Distribution<F>,
    Uniform: Distribution<G>,
    Uniform: Distribution<H>,
    Uniform: Distribution<I>,
    Uniform: Distribution<J>,
    Uniform: Distribution<K>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<A, B, C, D, E, F, G, H, I, J, K, L> Distribution<(A, B, C, D, E, F, G, H, I, J, K, L)> for Uniform where
    Uniform: Distribution<A>,
    Uniform: Distribution<B>,
    Uniform: Distribution<C>,
    Uniform: Distribution<D>,
    Uniform: Distribution<E>,
    Uniform: Distribution<F>,
    Uniform: Distribution<G>,
    Uniform: Distribution<H>,
    Uniform: Distribution<I>,
    Uniform: Distribution<J>,
    Uniform: Distribution<K>,
    Uniform: Distribution<L>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 0]> for Uniform
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 1]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 2]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 3]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 4]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 5]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 6]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 7]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 8]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 9]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 10]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 11]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 12]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 13]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 14]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 15]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 16]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 17]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 18]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 19]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 20]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 21]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 22]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 23]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 24]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 25]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 26]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 27]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 28]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 29]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 30]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 31]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<[T; 32]> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl<T> Distribution<Option<T>> for Uniform where
    Uniform: Distribution<T>, 
[src]

[src]

Generate a random value of T, using rng as the source of randomness. Read more

impl Debug for Uniform
[src]

[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for Uniform

impl Sync for Uniform