universalShuffleAlgorithm.sol, based on Algorithm P (Shuffle) (Knuth, 1969), Fisher–Yates shuffle (1938)
The algorithm can be applied for different types of use cases, including shuffling a population that grows from 0 to n people, "invasive shuffling". In the Pseudonym Pairs dApp, I use it for shuffling the population as a whole (using "invasive shuffling"), assigning people who opt-in to pairs that make up the "virtual borders" (using the method in the pickFromHat()
, see below), scheduling the pseudonym event for a random hour each month, cycling through 24 hours (same method as pickFromHat()
), letting people re-assign from pairs that were broken up (same as pickFromHat()
), and issuing border tokens to a random person for each border token that is sold (also same as pickFromHat()
).