Since the "roll randomly" rules are not explicitly described, this is how I do it.
I base it on the number of squares a creature occupies in three dimensions. A tall large creature occupies four squares below and four above for a total of 8 squares. An archer attacking a tall large creature grappling a medium creature would have a 1 in 9 chance of hitting the medium creature. I do not apply the firing into melee penalty unless the two are actually in melee with each other (i.e. threatening each other, which they are not while grappling). A long large creature occupies only four squares below for a total of 4 squares. Said archer would have a 1 in 5 chance of hitting the medium creature in this case. Determining whether a creature is tall or long is simply a matter of examining its reach. If its reach equals its space, then the creature is tall. If its reach is less than its space, then the creature is long.
Extrapolate this formula for huge, etc.
I ignore creatures size tiny or smaller (such as a familiar) for simplicity.