generation_num and population functions