Skip to content

Instantly share code, notes, and snippets.

@xpdlf1004
Last active May 15, 2018 08:20
Show Gist options
  • Save xpdlf1004/485e0c705d29813265a398d71f506937 to your computer and use it in GitHub Desktop.
Save xpdlf1004/485e0c705d29813265a398d71f506937 to your computer and use it in GitHub Desktop.
uint commitmentNumber;
bytes32 randomBytes;
function commitment() public onlyOperator {
commitmentNumber = block.number;
}
function _initRandom() internal {
require(commitmentNumber < block.number);
if (commitmentNumber < block.number - 255) {
randomBytes = block.blockhash(block.number - 1);
} else {
randomBytes = block.blockhash(commitmentNumber);
}
}
function _random256() internal returns(uint256) {
randomBytes = keccak256(randomBytes);
return uint256(randomBytes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment