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, const N: usize> Distrib for Uniform<[T; N]>
impl<T, const N: usize> Distrib for Uniform<[T; N]>
Source§fn sample(&self, rng: &mut DefaultRng) -> [T; N]
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§impl<Sc, Sp, const DIM: usize> Distrib for Uniform<Color<[Sc; DIM], Sp>>
impl<Sc, Sp, const DIM: usize> Distrib for Uniform<Color<[Sc; DIM], Sp>>
Source§impl<Sc, Sp, const DIM: usize> Distrib for Uniform<Point<[Sc; DIM], Sp>>
Uniformly distributed points within a rectangular volume.
impl<Sc, Sp, const DIM: usize> Distrib for Uniform<Point<[Sc; DIM], Sp>>
Uniformly distributed points within a rectangular volume.
Source§impl<Sc, Sp, const DIM: usize> Distrib for Uniform<Vector<[Sc; DIM], Sp>>
Uniformly distributed vectors within a rectangular volume.
impl<Sc, Sp, const DIM: usize> Distrib for Uniform<Vector<[Sc; DIM], Sp>>
Uniformly distributed vectors within a rectangular volume.
Source§impl Distrib for Uniform<f32>
Uniformly distributed floats.
impl Distrib for Uniform<f32>
Uniformly distributed floats.
Source§fn sample(&self, rng: &mut DefaultRng) -> f32
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§impl Distrib for Uniform<i32>
Uniformly distributed signed integers.
impl Distrib for Uniform<i32>
Uniformly distributed signed integers.
Source§fn sample(&self, rng: &mut DefaultRng) -> i32
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§impl Distrib for Uniform<u32>
Uniformly distributed unsigned integers.
impl Distrib for Uniform<u32>
Uniformly distributed unsigned integers.
Source§fn sample(&self, rng: &mut DefaultRng) -> u32
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§impl Distrib for Uniform<usize>
Uniformly distributed indices.
impl Distrib for Uniform<usize>
Uniformly distributed indices.
Source§fn sample(&self, rng: &mut DefaultRng) -> usize
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"]);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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more