Skip to content

Instantly share code, notes, and snippets.

@vbalko
Created October 21, 2021 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vbalko/fc49f9515fac036fc5860f434e6b830f to your computer and use it in GitHub Desktop.
Save vbalko/fc49f9515fac036fc5860f434e6b830f to your computer and use it in GitHub Desktop.
random function in solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* @title Storage
* @dev Store & retrieve value in a variable
*/
contract rand {
uint256 number;
function roll(uint _a, uint _b, uint _dx) public view returns (uint) {
return uint(keccak256(abi.encodePacked(block.timestamp, _a, _b)))%_dx + 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment