Generation II-IV
Conversion 2 will change the user's current type to a random type that either resists or is immune to the type of the last damaging move it was hit by.
Generation V
Conversion 2 now changes the user's type to make it resist the last move the target used.
Bulbapedia so if porygon used conversion 2 after the foe used drain punch, porygon will become a random type as long as it resists the last move fight, such as bug.