Function cgl_rs::utils::get_random_with_probability
source · pub fn get_random_with_probability(probabilities: &mut [f32]) -> usize
Expand description
Returns a random index from the given slice of probabilities, where the probability of each index being chosen is proportional to its value in the slice.
Arguments
probabilities
- A mutable slice off32
values representing the probabilities of each index being chosen.
Returns
- A
usize
representing the randomly chosen index.
Example
let mut probabilities = vec![0.1, 0.2, 0.3, 0.4];
let index = cgl_rs::utils::get_random_with_probability(&mut probabilities);