universalShuffleAlgorithm.sol, based on Algorithm P (Shuffle) (Knuth, 1969), Fisher–Yates shuffle (1938)

in #ethereum6 years ago (edited)

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()).

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 62014.91
ETH 2410.27
USDT 1.00
SBD 2.50