📜  在solidity中获取随机数 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:03:17.548000             🧑  作者: Mango

代码示例1
// Solidity pseudo-random function:
function random() private view returns (uint) {
  // sha3 and now have been deprecated
  return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, players)));
  // convert hash to integer
  // players is an array of entrants
}

// invoke random function in a pickWinner example function
function pickWinner() public {
  uint index=random()%players.length;
}