Just curious.
This question has sort of already been answered here: http://pokemondb.net/pokebase/90818/how-do-id-numbers-work Regardless, the Trainer ID is determined by the game randomly generating a 5-digit number from 00001 to 65535 when you start your journey. As show in this link, Trainer ID's may start being 6-digits long instead in Sun/Moon: http://bulbapedia.bulbagarden.net/wiki/Trainer_ID_number