It chooses the oldest one. In addition, if the oldest son sucks then you're gonna have a civil war. That's why I always keep the best son (full acumen, high command and piety) in the capital province and send the rest of heirs to war.