【solitidy编程】-生成随机数算法

栏目: 编程工具 · 发布时间: 7年前

内容简介:fomo3d的空投机制就是这中算法。以太坊代码:生成一个5位的随机数

通过区块因素

引用

fomo3d的空投机制就是这中算法。

以太坊代码:生成一个5位的随机数

uint256 winningNum = uint256(keccak256(abi.encodePacked(
                    (block.timestamp).add
                    (block.difficulty).add
                    ((uint256(keccak256(abi.encodePacked(block.coinbase)))) / (now)).add
                    (block.gaslimit).add
                    ((uint256(keccak256(abi.encodePacked(msg.sender)))) / (now)).add
                    (block.number)
                ))) % 100000;

转乘数字格式:

abi.encodePacked(
    block.timestamp +                                   // 区块的时间戳
    block.difficulty +                                  // 区块难度
    keccak256(abi.encodePacked(block.coinbase)) / now + // 矿工的地址hash 除去 区块的时间戳
    block.gaslimit +                                    // 区块的gas上线
    keccak256(abi.encodePacked(msg.sender)) / now +     // 开奖人的地址的hash值 除以 区块的时间戳
    block.number                                        // 区块的数量
    ) % 100000

随机数生成是由 区块的时间戳区块难度矿工的地址hash区块的gas上线开奖人地址区块的数量 等因随机数共同决定。

通过签名算法

Dice2Win


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Code

Code

Charles Petzold / Microsoft Press / 2000-10-21 / USD 29.99

Paperback Edition What do flashlights, the British invasion, black cats, and seesaws have to do with computers? In CODE, they show us the ingenious ways we manipulate language and invent new means of ......一起来看看 《Code》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

SHA 加密
SHA 加密

SHA 加密工具