You are viewing a single comment's thread from:

RE: Solidity开发指南

in #starnotelast month

solidity中并没有真正的随机数,不建议使用,最好使用预言机中的随机数功能。

random = uint256(keccak256(abi.encode(block.timestamp, admin, hash))) % 100;

eg:
uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;
function _generateRandomDna(string memory _str) public view returns (uint) {
  return uint(keccak256(abi.encodePacked(_str, block.timestamp))) % dnaModulus;
  //9758857365005908
}