Skip to content

Instantly share code, notes, and snippets.

@resilience-me
Last active November 10, 2018 18:52
Show Gist options
  • Save resilience-me/7433c4d3754ee228526a6462eec3e76c to your computer and use it in GitHub Desktop.
Save resilience-me/7433c4d3754ee228526a6462eec3e76c to your computer and use it in GitHub Desktop.
contract universalShuffleAlgorithm {
mapping(uint => uint) shuffleIndex;
uint counter;
mapping(address => uint) userID;
uint totalPopulation;
uint entropy;
function pickFromHat() {
uint randomNumber = 1 + getRandomNumber(entropy) % (totalPopulation - 1 - counter);
if(shuffleIndex[randomNumber] == 0) shuffleIndex[randomNumber] = randomNumber;
userID[msg.sender] = shuffleIndex[randomNumber];
if(shuffleIndex[totalPopulation - counter] == 0) shuffleIndex[totalPopulation - counter] = totalPopulation - counter;
shuffleIndex[randomNumber] = shuffleIndex[totalPopulation - counter];
counter++;
}
function getRandomNumber(uint _entropy) returns (uint) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment