[][src]Struct randomize::BoundedRandU32

pub struct BoundedRandU32 { /* fields omitted */ }

Stores the values to sample a number in 0 .. N

Making one of these performs a division operation. In comparison, Gen32::next_bounded will avoid needing to do a division much of the time. Thus, unless you need to sample repeatedly from a specific bounded range, simply calling next_bounded directly might be more efficient.

Implementations

impl BoundedRandU32[src]

pub const fn new(count: u32) -> Self[src]

Constructs a new BoundedRandU32.

Panics

If the count is 0.

pub const fn try_new(count: u32) -> Option<Self>[src]

Constructs a new BoundedRandU32, or None on failure.

Failure

If the count is 0.

pub const fn count(self) -> u32[src]

The number of possible outputs.

pub const fn place_in_range(self, val: u32) -> Option<u32>[src]

Given a u32, place it into this bounded range.

Failure

  • If the value is such that it doesn't fit evenly it is rejected.

pub fn sample<G: Gen32 + ?Sized>(self, gen: &mut G) -> u32[src]

Given a gen, sample from the gen until place_in_range succeeds.

Trait Implementations

impl Clone for BoundedRandU32[src]

impl Copy for BoundedRandU32[src]

impl Debug for BoundedRandU32[src]

impl Eq for BoundedRandU32[src]

impl Hash for BoundedRandU32[src]

impl PartialEq<BoundedRandU32> for BoundedRandU32[src]

impl StructuralEq for BoundedRandU32[src]

impl StructuralPartialEq for BoundedRandU32[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.