Created
February 14, 2018 16:06
-
-
Save nakov/b5aa36d36de8334f2df6a929b6f8cd0f to your computer and use it in GitHub Desktop.
Solidity Insecure Random Generator
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
// Insecure random generator for Solidity. Can be manipulated by the miners | |
contract InsecureRandomGenerator { | |
bytes32 public randseed; | |
function pseudoRandom(uint start, uint end) returns (uint) { | |
bytes32 prevBlockHash = block.blockhash(block.number-1); | |
randseed = keccak256(randseed, prevBlockHash, block.timestamp, | |
block.coinbase, block.difficulty, block.number); | |
uint range = end - start + 1; | |
uint randVal = start + uint256(randseed) % range; | |
return randVal; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment