Created
May 15, 2018 10:06
-
-
Save xpdlf1004/3d9bb193f8ef9a341fa517ba71c9378d 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
function _shuffle(uint8[] deck) internal { | |
require(deck.length < 256); | |
uint8 deckLength = uint8(deck.length); | |
uint8 random; | |
for (uint8 i = 0; i < deckLength; i++) { | |
if (i % 32 == 0) { | |
randomBytes = keccak256(randomBytes); | |
} | |
random = uint8(randomBytes[i % 32]) % (deckLength - i); | |
if (random != deckLength - 1 - i) { | |
deck[random] ^= deck[deckLength - 1 - i]; | |
deck[deckLength - 1 - i] ^= deck[random]; | |
deck[random] ^= deck[deckLength - 1 - i]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment