No need to do this. Just use random() % maxElementCountPerCollection + 1.