I am wondering if there is a ‘best’ way to shuffle a list of elements that contains duplicates such that the case where array[i] == array[i+1] is avoided as much as possible.
I am working on a weighted advertising display (I can adjust the number of displays per rotation for any given advertiser) and would like to avoid the same advertister appearing twice in a row.
For reference, my (very) naive approach was something like this (actually using LINQ/SQL calls but this is simplified):
This will avoid duplicates until the end but yeah it would pay to check backwards through the returnList afterwards and if there are any duplicates tailing, try and place them in the mix earlier.