It became the practice for Chinese emperors, starting thousands of years ago, to keep teams of eunuchs around the women’s quarters, to make sure the ladies weren’t having sex with other males.
In times of high infant mortality rates, procreating with the wives and concubines helped guarantee an heir to the throne. The wives got first dibs, lineage-wise, but if none of the wives had sons, the heir apparent came from the concubines’ sons.
It’s a system that usually worked just fine; however, there have been exceptions. A new dynasty was often started as a result of rebellions and uprisings. The various dynasties were not related to one another.
The Ming dynasty’s first emperor, for instance, was from a lower-class peasant background; he was not a relative of the noble class.
He happened to be the leader of a fairly strong rebellion, and his lineage lasted for about three centuries.