是否可以使用 Solidity 创建不可预测的随机数?
Is it possible to create unpredictable random number with Solidity?
我最近一直在研究这个话题,大多数资源都说不可能在链上生成随机数。然而,我遇到了一个 post 说这个函数可以生成一个不可预测的数字。有什么方法可以预测这个功能吗?
function rand() public view returns(uint256) {
uint256 seed = uint256(keccak256(abi.encodePacked(
block.timestamp + block.difficulty +
((uint256(keccak256(abi.encodePacked(block.coinbase)))) / (now)) +
block.gaslimit +
((uint256(keccak256(abi.encodePacked(msg.sender)))) / (now)) +
block.number
)));
return (seed - ((seed / 1000) * 1000));
}
Is there any way to predict this function?
矿工可以发布他们的区块 number
,其 timestamp
符合其他标准:
difficulty
给了一段时间
coinbase
给出的时间更长
msg.sender
(真正的交易发送者和签名者)可以是矿工地址之一
没有办法在链上生成真正不可确定的随机数。但是您可以使用 returns 链下生成的“随机”数字的预言机。
我最近一直在研究这个话题,大多数资源都说不可能在链上生成随机数。然而,我遇到了一个 post 说这个函数可以生成一个不可预测的数字。有什么方法可以预测这个功能吗?
function rand() public view returns(uint256) {
uint256 seed = uint256(keccak256(abi.encodePacked(
block.timestamp + block.difficulty +
((uint256(keccak256(abi.encodePacked(block.coinbase)))) / (now)) +
block.gaslimit +
((uint256(keccak256(abi.encodePacked(msg.sender)))) / (now)) +
block.number
)));
return (seed - ((seed / 1000) * 1000));
}
Is there any way to predict this function?
矿工可以发布他们的区块 number
,其 timestamp
符合其他标准:
difficulty
给了一段时间coinbase
给出的时间更长msg.sender
(真正的交易发送者和签名者)可以是矿工地址之一
没有办法在链上生成真正不可确定的随机数。但是您可以使用 returns 链下生成的“随机”数字的预言机。