【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


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

查看所有标签

猜你喜欢:

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

Trading and Exchanges

Trading and Exchanges

Larry Harris / Oxford University Press, USA / 2002-10-24 / USD 95.00

This book is about trading, the people who trade securities and contracts, the marketplaces where they trade, and the rules that govern it. Readers will learn about investors, brokers, dealers, arbit......一起来看看 《Trading and Exchanges》 这本书的介绍吧!

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

在线压缩/解压 JS 代码

在线进制转换器
在线进制转换器

各进制数互转换器

html转js在线工具
html转js在线工具

html转js在线工具