Male robots have a USB flashdrive with half of an OS. Female robots have a USB port with another half of an OS. When they're combined, both robots generate so much electricity that it makes the mana around them crazy and a small R2D2 is born with a random bool of being female or not.
excus u, u are limiting your scope of robots to simply things that could be created by humans
u r completely ignoring the possibility of sentient alien robots