I Chron. 23:1-24:31
As David prepared Israel for their new king, he called a meeting of the nation’s leaders. Many years earlier, God had separated the tribe of Levi as Levites to perform the various duties of the worship assemblies. Aaron and his sons had been designated to be the priests. There were four main divisions of the responsibilities that David addressed in those closing days of his reign as king. Most of them were responsible for seeing to the work of the house of the Lord which was to be built soon. Some were officers and judges. Others were gatekeepers. Those remaining were musicians responsible for praising the Lord with musical instruments.
David was precise as he listed the various groups and leaders to perform the priestly duties. As a method of ensuring order and possibly fairness and to prevent jealousy, lots were cast to determine the times that the various priestly divisions would be responsible to serve.