Or make a unit group, put in all units of the same unit type -> Pick every unit in playable map area matching (unit-type of matching unit) equal to (unit-type of (last created unit)) and do if the number of this unit group is greater than 1, pick 1 random unit of this group and replace it by the a random one. (Random integer between 1 and 24 i.e.)