fn select_point(distribution: &[f64]) -> usize {
        // Generate the selection criterion for each point.
        // We'll generate a random number and select the point whose selection criterion is less
        // than that number, but whose following point's is greater than that number.
        // Like throwing a dart at a number line and seeing what range of values it falls in.
        let distr_sum = distribution.iter().fold(0.0, f64::add);
        let mut selection_criteria = Vec::with_capacity(distribution.len());
        for i in 0..distribution.len() {
            let sum = distribution[0..i].iter().fold(0.0, f64::add);
            selection_criteria.push(distribution[i] + sum);
        }
        let rn: f64 = thread_rng().gen_range(0.0, distr_sum);

        let mut selection = 0;
        for i in 1..(selection_criteria.len() - 1) {
            if rn > selection_criteria[i] {
                selection = i;
            }

            if rn <= selection_criteria[i] {
                break;
            }
        }

        selection
    }
/// Selects a point using a weighted distribution based on `shortest_center_distance` squared.
Selects a point using a weighted distribution based on `shortest_center_distance` squared.
Selects a point using a weighted distribution based on ` shortest_center_distance ` squared .
fn select_point(distribution: &[f64]) -> usize {
        // Generate the selection criterion for each point.
        // We'll generate a random number and select the point whose selection criterion is less
        // than that number, but whose following point's is greater than that number.
        // Like throwing a dart at a number line and seeing what range of values it falls in.
        let distr_sum = distribution.iter().fold(0.0, f64::add);
        let mut selection_criteria = Vec::with_capacity(distribution.len());
        for i in 0..distribution.len() {
            let sum = distribution[0..i].iter().fold(0.0, f64::add);
            selection_criteria.push(distribution[i] + sum);
        }
        let rn: f64 = thread_rng().gen_range(0.0, distr_sum);
        let mut selection = 0;
        for i in 1..(selection_criteria.len() - 1) {
            if rn > selection_criteria[i] {
                selection = i;
            }
            if rn <= selection_criteria[i] {
                break;
            }
        }
        selection
    }
fn select_point ( distribution : & [ f64 ] ) -> usize { // Generate the selection criterion for each point. // We'll generate a random number and select the point whose selection criterion is less // than that number, but whose following point's is greater than that number. // Like throwing a dart at a number line and seeing what range of values it falls in. let distr_sum = distribution . iter ( ) . fold ( 0.0 , f64 :: add ) ; let mut selection_criteria = Vec :: with_capacity ( distribution . len ( ) ) ; for i in 0 .. distribution . len ( ) { let sum = distribution [ 0 .. i ] . iter ( ) . fold ( 0.0 , f64 :: add ) ; selection_criteria . push ( distribution [ i ] + sum ) ; } let rn : f64 = thread_rng ( ) . gen_range ( 0.0 , distr_sum ) ; let mut selection = 0 ; for i in 1 .. ( selection_criteria . len ( ) - 1 ) { if rn > selection_criteria [ i ] { selection = i ; } if rn <= selection_criteria [ i ] { break ; } } selection }
Selects a point using a weighted distribution based on `shortest_center_distance` squared.
Selects a point using a weighted distribution based on ` shortest_center_distance ` squared .
distribution
&[f64]
distribution
&[f64]