Skip to content

Instantly share code, notes, and snippets.

Created February 14, 2018 16:06
What would you like to do?
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