Skip to content

Instantly share code, notes, and snippets.

@yhuag
Created December 2, 2018 02:00
Show Gist options
  • Save yhuag/70f0f3477ce19001b45303430951c0ed to your computer and use it in GitHub Desktop.
Save yhuag/70f0f3477ce19001b45303430951c0ed to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.21;
contract Random {
function getBlockNum() public constant returns (uint) {
return block.number;
}
function getNow() public constant returns (uint) {
return now;
}
function getNow2() public constant returns (uint) {
return block.timestamp;
}
function randNow(uint min, uint max) public constant returns (uint) {
return (getNow() % (max - min)) + min;
}
function randHash(uint min, uint max) public constant returns (uint){
bytes32 hash = keccak256(getNow());
return (uint(hash) % (max - min)) + min;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment