Trait IndexedMutRandom

Source
pub trait IndexedMutRandom: IndexedRandom + IndexMut<usize> {
    // Provided method
    fn choose_mut<R>(&mut self, rng: &mut R) -> Option<&mut Self::Output>
       where R: Rng + ?Sized { ... }
}
Expand description

Extension trait on indexable lists, providing random sampling methods.

This trait is implemented automatically for every type implementing IndexedRandom and [std::ops::IndexMut<usize>].

Provided Methods§

Source

fn choose_mut<R>(&mut self, rng: &mut R) -> Option<&mut Self::Output>
where R: Rng + ?Sized,

Uniformly sample one element (mut)

Returns a mutable reference to one uniformly-sampled random element of the slice, or None if the slice is empty.

For slices, complexity is O(1).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§