Skip to main content

ScientificSliceRandom

Trait ScientificSliceRandom 

Source
pub trait ScientificSliceRandom<T> {
    // Required methods
    fn scientific_shuffle<R>(&mut self, rng: &mut Random<R>)
       where R: Rng;
    fn scientific_choose<R>(&self, rng: &mut Random<R>) -> Option<&T>
       where R: Rng;
    fn scientific_choose_multiple<R>(
        &self,
        rng: &mut Random<R>,
        amount: usize,
    ) -> Vec<&T>
       where R: Rng;
    fn scientific_sample_with_replacement<R>(
        &self,
        rng: &mut Random<R>,
        amount: usize,
    ) -> Vec<&T>
       where R: Rng;
    fn scientific_weighted_sample<R, W>(
        &self,
        rng: &mut Random<R>,
        weights: &[W],
        amount: usize,
    ) -> Result<Vec<&T>, String>
       where R: Rng,
             W: Into<f64> + Copy;
    fn scientific_reservoir_sample<R>(
        &self,
        rng: &mut Random<R>,
        k: usize,
    ) -> Vec<&T>
       where R: Rng;
}
Expand description

Enhanced slice random operations for scientific computing

Required Methods§

Source

fn scientific_shuffle<R>(&mut self, rng: &mut Random<R>)
where R: Rng,

Shuffle the slice in place with enhanced performance

Source

fn scientific_choose<R>(&self, rng: &mut Random<R>) -> Option<&T>
where R: Rng,

Choose a random element with guaranteed uniform distribution

Source

fn scientific_choose_multiple<R>( &self, rng: &mut Random<R>, amount: usize, ) -> Vec<&T>
where R: Rng,

Choose multiple elements without replacement using optimal algorithms

Source

fn scientific_sample_with_replacement<R>( &self, rng: &mut Random<R>, amount: usize, ) -> Vec<&T>
where R: Rng,

Sample with replacement

Source

fn scientific_weighted_sample<R, W>( &self, rng: &mut Random<R>, weights: &[W], amount: usize, ) -> Result<Vec<&T>, String>
where R: Rng, W: Into<f64> + Copy,

Weighted sampling (requires weights)

Source

fn scientific_reservoir_sample<R>( &self, rng: &mut Random<R>, k: usize, ) -> Vec<&T>
where R: Rng,

Reservoir sampling for streaming data

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T> ScientificSliceRandom<T> for Vec<T>

Source§

fn scientific_shuffle<R>(&mut self, rng: &mut Random<R>)
where R: Rng,

Source§

fn scientific_choose<R>(&self, rng: &mut Random<R>) -> Option<&T>
where R: Rng,

Source§

fn scientific_choose_multiple<R>( &self, rng: &mut Random<R>, amount: usize, ) -> Vec<&T>
where R: Rng,

Source§

fn scientific_sample_with_replacement<R>( &self, rng: &mut Random<R>, amount: usize, ) -> Vec<&T>
where R: Rng,

Source§

fn scientific_weighted_sample<R, W>( &self, rng: &mut Random<R>, weights: &[W], amount: usize, ) -> Result<Vec<&T>, String>
where R: Rng, W: Into<f64> + Copy,

Source§

fn scientific_reservoir_sample<R>( &self, rng: &mut Random<R>, k: usize, ) -> Vec<&T>
where R: Rng,

Source§

impl<T> ScientificSliceRandom<T> for [T]

Source§

fn scientific_shuffle<R>(&mut self, rng: &mut Random<R>)
where R: Rng,

Source§

fn scientific_choose<R>(&self, rng: &mut Random<R>) -> Option<&T>
where R: Rng,

Source§

fn scientific_choose_multiple<R>( &self, rng: &mut Random<R>, amount: usize, ) -> Vec<&T>
where R: Rng,

Source§

fn scientific_sample_with_replacement<R>( &self, rng: &mut Random<R>, amount: usize, ) -> Vec<&T>
where R: Rng,

Source§

fn scientific_weighted_sample<R, W>( &self, rng: &mut Random<R>, weights: &[W], amount: usize, ) -> Result<Vec<&T>, String>
where R: Rng, W: Into<f64> + Copy,

Source§

fn scientific_reservoir_sample<R>( &self, rng: &mut Random<R>, k: usize, ) -> Vec<&T>
where R: Rng,

Implementors§