Hi,

I implemented the stochastic universal sampling algorithm. One variant works with f32 and one with f64 and for some reason, I can provoke an index out of bounds panicks with the f32 variant, which is almost identical with the f64 variant.

```
pub fn random_choice_f32<'a, T>(samples: &'a [T], weights: &[f32], n: usize) -> Vec<&'a T> {
if weights.len() == 0 || n == 0 {
return Vec::new();
}
let sum: f32 = weights.iter().fold(0.0, |acc, &i| acc + i);
let spoke_gap: f32 = sum / n as f32;
// next_f32() ∈ [0.0, 1.0)
let spin = thread_rng().next_f32() * spoke_gap;
let mut i: usize = 0;
let mut accumulated_weights = weights[0];
let mut choices: Vec<&T> = Vec::with_capacity(n);
let mut current_spoke: f32 = spin;
println!("sum: {}, gap: {}", sum, spoke_gap);
for j in 0..n {
while accumulated_weights < current_spoke {
println!("accumulated_weights: {}, current_spoke: {}, spoke number: {}, i: {}", accumulated_weights, current_spoke, j, i);
i += 1;
accumulated_weights += weights[i];
}
choices.push(&samples[i]);
current_spoke += spoke_gap;
}
choices
}
```

The f64 variant is absolute identical, except it uses f64.

Following test provokes an index out of bounds panick:

```
#[test]
fn test_random_choice_f32() {
let capacity: usize = 500;
let mut samples: Vec<usize> = Vec::with_capacity(capacity);
let mut weights: Vec<f32> = Vec::with_capacity(capacity);
for i in 0..capacity {
samples.push(i);
weights.push(i as f32);
}
let number_choices = 10000;
let choices = RandomChoice::random_choice_f32(&samples, &weights, number_choices);
assert!(choices.len() == number_choices);
let mut weight_counter = BTreeMap::new();
for choice in choices {
let counter = weight_counter.entry(choice).or_insert(0);
*counter += 1;
}
let mut last_value: usize = 0;
for (_, value) in &weight_counter {
assert!((last_value as i32 - (*value) as i32).abs() <= 2);
last_value = *value;
}
}
```

The f64 test never panicked and the pseudo code you find in wiki, looks almost identical.

Anyone any idea? You can find the code on github.

Thanks in advance!