Last active
November 10, 2018 18:52
-
-
Save resilience-me/7433c4d3754ee228526a6462eec3e76c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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