“Prior to Generation VI, because Azurill’s gender ratio does not match that of its evolved forms and its evolution is not dependent on gender, being female 75% of the time while Marill and Azumarill are female only 50% of the time, female Azurill has a 1/3 chance of evolving into a male Marill (depending on its personality value). Azurill is the only Pokémon to do this. From Generation VI on, Azurill retains its gender upon evolving, despite the gender ratios still differing.” From Bulbapedia’s list of Pokemon by gender ratio, in the Trivia section
Somebody deliberately had to code something different for this