I have a list of competitors and their respective horses, with each competitor identified by a unique ID, and competitors may be associated with different horses. I need to shuffle the list in such a way that the same competitor does not appear consecutively, ideally maintaining a minimum distance of 5 competitors between repetitions.
Do I need to apply this logic directly in the select query or through PHP.
I considered separating the items into groups and shuffling them, but there is a possibility that an item could be the last of one group and the first of another, causing them to be close together. However, the client requested that the order be shuffled, but items with the same ID cannot be close to each other, ideally with a distance of at least 5 competitors between them.