Last active
May 15, 2018 08:20
-
-
Save xpdlf1004/485e0c705d29813265a398d71f506937 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
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