How about you just tell it instead of some stupid link
To be fair the question is over-answered and kind of stupid at this point. So. . . Stupid question gets a stupid link?
To be nice: The Pokemon is generated the moment you receive the egg. So no matter what, the Pokemon will always be the same no matter how many times you hatch it or transfer it around (assuming you saved after receiving the egg). It i generated nearly the same way as normal Pokemon are, except other things are taken into account.
Destiny Knot: 5 different IV types will be chosen from the parent Pokemon. The EXACT numbers of either ones. So basically if you have 31 IVs in all stats on one Pokemon and 20 IVs in all stats on one Pokemon, you will get either 31/20 in 5 different IVs, while the 6th one will be randomly chosen from 0-31.
Everstone: Now passes nature at 100%. So if the everstone is on, the game generates the same natured Pokemon. Simple enough to understand, unlike the destiny knot thing at first.
If you want a real answer, each pokemon has a pseudo-random 32-bit number attached to it at the moment of creation, called PID. The lowest byte of PID determines the gender: if the integer value is more than the threshold, it's male; otherwise it's female.