Skip to content

Instantly share code, notes, and snippets.

@xpdlf1004
Created May 15, 2018 10:06
Show Gist options
  • Save xpdlf1004/3d9bb193f8ef9a341fa517ba71c9378d to your computer and use it in GitHub Desktop.
Save xpdlf1004/3d9bb193f8ef9a341fa517ba71c9378d to your computer and use it in GitHub Desktop.
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