https://scratch.mit.edu/discuss/topic/857529/ sums up every (1/rarity) and then picks random. This program also visually shows how this program picks an enemy; the length of each colored bar at the bottom corresponds to the enemie's rarity. Then the arrow points to the corresponding color.