My main advice is don't. A lot of people are going to explain why, so I won't bother with that.
But in general, if you're going to anyway... don't do it at night or in a situation where the girl is in any way "stuck" with you. So don't corner her somewhere, or say something in an elevator or on public transit unless you're just about to leave, or when you're both walking the same direction. That is scary, because even if you're a fantastic person who'd never hurt a fly, I have no way of knowing that, and it only takes one run-in with someone nasty to get raped or murdered (or mugged I guess).
Don't comment on a body part below her face, there's no non-weird way to do that to a stranger- makeup, clothes, and hair are more okay because they're stuff that a lady had to put time into, so it's more like complimenting an accomplishment than just her happening to have nice tits.
Don't say "nice tits" or anything even vaguely like it.
Don't expect her to respond positively, or at all. Seriously, if she tells you to fuck off, that's probably because your compliment came after an entire day and lifetime of much grosser catcalls, so if she doesn't wanna react nice to strangers commenting on her appearance, she isn't obligated to. No one is entitled to getting to talk about someone else's body, right? What a weird thing to have a right to do without the person in question voicing their annoyance. Free speech goes both ways yo. But yeah, even if she says thank you or reacts positively, don't like... expect that, or expect that to lead to her wanting to talk more to you, or to fuck you then and there. If she doesn't seem interested in further conversation, don't get angry or try to press the issue (even politely). Seriously, once again, you might be the nicest guy in the world, but being a lady, it's scary when a dude (or male-reading nonbinary person) won't take no for an answer. That is what rapists do, and once again, we have no reason to think that you aren't one, but now we have at least one reason to know you don't respect it when we say "no".
So yeah, I guess the ideal random street compliment would be one in broad daylight, surrounded by other people, when I'm clearly not walking in a hurry with headphones on or anything, where you quietly and politely get my attention and say "excuse me, I'm sorry to bother you but I just wanted to say that your shirt fantastic," and then you walk off after I respond with anything that isn't more active conversation.
But honestly I still don't see why you need to. Women's appearance gets focused on enough as it is, you really gotta contribute to that?