With the help of Zadok and Ahimelech, David separated the priests into groups. Each group served in its appointed order and time. Zadok belonged to the family line of Eleazar. Ahimelech belonged to the family line of Ithamar.
More leaders were found among Eleazar's family line than among Ithamar's. So the priests were separated into their groups based on that fact. There were 16 family leaders from Eleazar's line. There were eight family leaders from Ithamar's line.
The priests were separated into their groups by using lots. That was the fair way to do it. The priests were officials of the temple and officials of God. They came from the family lines of Eleazar and Ithamar.
Shemaiah was a Levite. He was the son of Nethanel. He was the writer who recorded the names of the priests. He wrote them down in front of the king and the officials. The officials included the priest Zadok and Ahimelech. Ahimelech was the son of Abiathar. They also included the leaders of the families of the priests and the Levites. One family was chosen by lot from Eleazar. Then one was chosen from Ithamar.
That was their appointed order for serving when they entered the Lord's temple. That order was based on the rules Aaron had given them long ago. Everything was done exactly as the Lord had commanded Aaron. The Lord is the God of Israel.
They cast lots, just as their relatives, the sons of Aaron, had done. They did it in front of King David, Zadok and Ahimelech. They did it in front of the family leaders of the priests. They also did it in front of the family leaders of the Levites. The families of the oldest brother were treated in the same way as the families of the youngest.