Function get_random_champion

Source
pub fn get_random_champion(champions: Vec<ChampionData>) -> ChampionData
Expand 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: A Vec<ChampionData> containing the list of champions from which a random champion will be selected.

§Returns:

  • ChampionData: A clone of the randomly selected ChampionData object.

§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 rand crate 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.
  • get_list_champions: Retrieves a list of champions that can be passed to this function to select a random one.

§Dependencies:

  • Requires the rand crate for generating a random index.