It's not exactly random. It's weighted. If there are a lot more girls in town, baby boys will be more common regardless of your efforts. I'm not exactly sure if SP uses overall demographics or demographics of a specific age group, but the reason it does this is to prevent your town from becoming like China (5 boys for every girl or vice versa). It promotes a healthier population growth.
If you have Master Controller as well though, you can just click the sim, go to Sim Options, select baby, and select the gender manually. Granted, this is a thread about watermelons and apples, so I'll throw in my two cents.
I have never had watermelons and apples fail, except when I got triplets, I have yet to get three triplets of the same gender. I prefer to play with girl sims, and so my pregnant sims eat watermelon. Not all the time, and only after they spin into maternity clothes. They eat... five to seven I believe, and it always has worked for me. I've done this... gosh, probably four dozen times or so?