Uniform

Struct Uniform 

Source
pub struct Uniform<T>(pub Range<T>);
Expand description

A uniform distribution of values in a range.

Tuple Fields§

§0: Range<T>

Trait Implementations§

Source§

impl<T: Clone> Clone for Uniform<T>

Source§

fn clone(&self) -> Uniform<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Uniform<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, const N: usize> Distrib for Uniform<[T; N]>
where T: Copy, Uniform<T>: Distrib<Sample = T>,

Source§

fn sample(&self, rng: &mut DefaultRng) -> [T; N]

Returns the coordinates of a point sampled from a uniform distribution within the N-dimensional rectangular volume bounded by self.0.

§Examples
use retrofire_core::math::rand::*;
let rng = &mut DefaultRng::default();

// Pairs of integers [X, Y] such that 0 <= X < 4 and -2 <= Y <= 3
let mut int_pairs = Uniform([0, -2]..[4, 3]).samples(rng);

assert_eq!(int_pairs.next(), Some([0, -1]));
assert_eq!(int_pairs.next(), Some([1, 0]));
assert_eq!(int_pairs.next(), Some([3, 1]));
Source§

type Sample = [T; N]

The type of the elements of the sample space of Self, also called “outcomes”.
Source§

fn samples(&self, rng: &mut DefaultRng) -> impl Iterator<Item = Self::Sample>

Returns an iterator that yields samples from self indefinitely. Read more
Source§

impl<Sc, Sp, const DIM: usize> Distrib for Uniform<Color<[Sc; DIM], Sp>>
where Sc: Copy, Sp: Clone, Uniform<[Sc; DIM]>: Distrib<Sample = [Sc; DIM]>,

Source§

fn sample(&self, rng: &mut DefaultRng) -> Self::Sample

Returns a point uniformly sampled from the rectangular volume bounded by self.0.

Source§

type Sample = Point<[Sc; DIM], Sp>

The type of the elements of the sample space of Self, also called “outcomes”.
Source§

fn samples(&self, rng: &mut DefaultRng) -> impl Iterator<Item = Self::Sample>

Returns an iterator that yields samples from self indefinitely. Read more
Source§

impl<Sc, Sp, const DIM: usize> Distrib for Uniform<Point<[Sc; DIM], Sp>>
where Sc: Copy, Uniform<[Sc; DIM]>: Distrib<Sample = [Sc; DIM]>,

Uniformly distributed points within a rectangular volume.

Source§

fn sample(&self, rng: &mut DefaultRng) -> Self::Sample

Returns a point uniformly sampled from the rectangular volume bounded by self.0.

Source§

type Sample = Point<[Sc; DIM], Sp>

The type of the elements of the sample space of Self, also called “outcomes”.
Source§

fn samples(&self, rng: &mut DefaultRng) -> impl Iterator<Item = Self::Sample>

Returns an iterator that yields samples from self indefinitely. Read more
Source§

impl<Sc, Sp, const DIM: usize> Distrib for Uniform<Vector<[Sc; DIM], Sp>>
where Sc: Copy, Uniform<[Sc; DIM]>: Distrib<Sample = [Sc; DIM]>,

Uniformly distributed vectors within a rectangular volume.

Source§

fn sample(&self, rng: &mut DefaultRng) -> Self::Sample

Returns a vector uniformly sampled from the rectangular volume bounded by self.0.

Source§

type Sample = Vector<[Sc; DIM], Sp>

The type of the elements of the sample space of Self, also called “outcomes”.
Source§

fn samples(&self, rng: &mut DefaultRng) -> impl Iterator<Item = Self::Sample>

Returns an iterator that yields samples from self indefinitely. Read more
Source§

impl Distrib for Uniform<f32>

Uniformly distributed floats.

Source§

fn sample(&self, rng: &mut DefaultRng) -> f32

Returns a uniformly distributed f32 in the range.

§Examples
use retrofire_core::math::rand::*;
let rng = &mut DefaultRng::default();

// Floats in the interval [-1, 1)
let mut iter = Uniform(-1.0..1.0).samples(rng);
assert_eq!(iter.next(), Some(0.19692874));
assert_eq!(iter.next(), Some(-0.7686298));
assert_eq!(iter.next(), Some(0.91969657));
Source§

type Sample = f32

The type of the elements of the sample space of Self, also called “outcomes”.
Source§

fn samples(&self, rng: &mut DefaultRng) -> impl Iterator<Item = Self::Sample>

Returns an iterator that yields samples from self indefinitely. Read more
Source§

impl Distrib for Uniform<i32>

Uniformly distributed signed integers.

Source§

fn sample(&self, rng: &mut DefaultRng) -> i32

Returns a uniformly distributed i32 in the range.

§Examples
use retrofire_core::math::rand::*;
let rng = &mut DefaultRng::default();


let mut iter = Uniform(-5i32..6).samples(rng);
assert_eq!(iter.next(), Some(0));
assert_eq!(iter.next(), Some(4));
assert_eq!(iter.next(), Some(5));
Source§

type Sample = i32

The type of the elements of the sample space of Self, also called “outcomes”.
Source§

fn samples(&self, rng: &mut DefaultRng) -> impl Iterator<Item = Self::Sample>

Returns an iterator that yields samples from self indefinitely. Read more
Source§

impl Distrib for Uniform<u32>

Uniformly distributed unsigned integers.

Source§

fn sample(&self, rng: &mut DefaultRng) -> u32

Returns a uniformly distributed u32 in the range.

§Examples
use retrofire_core::math::rand::*;
let rng = &mut DefaultRng::from_seed(1234);

// Simulate rolling a six-sided die
let mut rolls: Vec<_>  = Uniform(1u32..7)
    .samples(rng)
    .take(6)
    .collect();
assert_eq!(rolls, [2, 4, 6, 6, 3, 1]);
Source§

type Sample = u32

The type of the elements of the sample space of Self, also called “outcomes”.
Source§

fn samples(&self, rng: &mut DefaultRng) -> impl Iterator<Item = Self::Sample>

Returns an iterator that yields samples from self indefinitely. Read more
Source§

impl Distrib for Uniform<usize>

Uniformly distributed indices.

Source§

fn sample(&self, rng: &mut DefaultRng) -> usize

Returns a uniformly distributed usize in the range.

§Examples
use retrofire_core::math::rand::*;
let rng = &mut DefaultRng::default();

// Randomly sample elements from a list (with replacement)
let beverages = ["water", "tea", "coffee", "Coke", "Red Bull"];
let mut x: Vec<_> = Uniform(0..beverages.len())
    .samples(rng)
    .take(3)
    .map(|i| beverages[i])
    .collect();

assert_eq!(x, ["water", "tea", "Red Bull"]);
Source§

type Sample = usize

The type of the elements of the sample space of Self, also called “outcomes”.
Source§

fn samples(&self, rng: &mut DefaultRng) -> impl Iterator<Item = Self::Sample>

Returns an iterator that yields samples from self indefinitely. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Uniform<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Uniform<T>
where T: RefUnwindSafe,

§

impl<T> Send for Uniform<T>
where T: Send,

§

impl<T> Sync for Uniform<T>
where T: Sync,

§

impl<T> Unpin for Uniform<T>
where T: Unpin,

§

impl<T> UnwindSafe for Uniform<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.