Skip to content

Instantly share code, notes, and snippets.

@nakov
Created February 14, 2018 16:06
Show Gist options
  • Save nakov/b5aa36d36de8334f2df6a929b6f8cd0f to your computer and use it in GitHub Desktop.
Save nakov/b5aa36d36de8334f2df6a929b6f8cd0f to your computer and use it in GitHub Desktop.
Solidity Insecure Random Generator
// 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