findGeneration function

Determines the generation number for each id.