tomazos,
Assuming it does the right thing, you are going to want to use the integer partitioning code blokhead refers to above and the binary counting I explained. You will not have a contigous range of team reference numbers but they will be guaranteed to be unique and will never be higher than 2 ** $num_of_people.
If I find the time tonight or tomorrow, I will code this for you. If you end up coding it on your own, please post so others can benefit and I won't bother.