I want to create a function that spawns NPCs based on an adjustable percent. For example, let’s say we have 3 types of monsters, A,B, and C. Before starting the game, the player can choose to set their spawn rates. By default, A, B, and C each have a 33.33…% chance to generate. If the player wants to spawn zero monster Cs, then the ratio will change to a 50-50 split for monsters A and B. Hopefully that part is clear, because the next part is where I am struggling.
I have three variables established for each monster’s spawn frequency. I have the system in place so that these all adjust when the player changes one of the settings. How would I go about creating a function that looks at each spawn frequency variable and generating a monster based on their respective frequencies? I thought about using if statements like If (random number) <=33.33…, spawn type A, if (random number) <= 66.66… and >=33.33… spawn type B, etc.
I am more so looking for advice on the logical structure, since I am most likely making this more complicated than necessary. Any help would be appreciated. Thanks!