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 uniformly distributed point within
the N-dimensional rectangular volume bounded by the range self.0.
§Examples
use retrofire_core::math::rand::*;
let rng = DefaultRng::default();
// Pairs of integers [X, Y] such that 0 <= X < 4 and -2 <= Y <= 3
let mut iter = Uniform([0, -2]..[4, 3]).samples(rng);
assert_eq!(iter.next(), Some([0, -1]));
assert_eq!(iter.next(), Some([1, 0]));
assert_eq!(iter.next(), Some([3, 1]));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 = 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 integers.
impl Distrib for Uniform<i32>
Uniformly distributed 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 = DefaultRng::default();
// Simulate rolling a six-sided die
let mut iter = Uniform(1..7).samples(rng);
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(4));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