It doesn't actually say "50% chance to hit either."
It says "roll randomly to see which combatant you hit."
If a purple worm is grappling the halfling, the DM might rule that a Gargantuan creature counts as 16 Small creatures, so there is a 1-in-17 chance of hitting the halfling and a 16-in-17 chance of hitting the worm (roll 1d20, reroll 18-20). That's still "roll randomly."