it's mostly being born to a) rich parents who can afford to pay for extra-curricular activity, good schools or who have the time to "improve" their kids or b) being around schools or universities that can recognise the talent and give talented kids the input and resources they need. Both a) and b) are based on pure luck.
For an example, check out Bill Gates' early life: https://en.wikipedia.org/wiki/Bill_Gates#Early_life
Rich parents, exclusive school (with their own computer! unheard of at the time) and local companies that let Gates and other kids screw around on their computers. Luck!