pub fn get_random_champion(champions: Vec<ChampionData>) -> ChampionDataExpand description
⚙️ Selects a random champion from a list of ChampionData.
This function takes a vector of ChampionData and returns a random champion from that list.
It uses a random number generator to choose an index, ensuring that each champion has an equal chance of being selected.
§Parameters:
champions: AVec<ChampionData>containing the list of champions from which a random champion will be selected.
§Returns:
ChampionData: A clone of the randomly selectedChampionDataobject.
§Example:
let champions_list = vec![champion1, champion2, champion3];
let random_champion = get_random_champion(champions_list);
println!("Selected Champion: {}", random_champion.name);§⚠️ Notes:
- The function uses the
randcrate to generate a random index, and selects the champion at that index. - The selected champion is cloned before being returned, ensuring the original vector remains unmodified.
§Related Functions:
get_list_champions: Retrieves a list of champions that can be passed to this function to select a random one.
§Dependencies:
- Requires the
randcrate for generating a random index.