6

怎么在eth链上产生1~5的随机数

 3 years ago
source link: https://learnblockchain.cn/question/1855
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
怎么在eth链上产生1~5的随机数 | 登链社区 | 技术问答

怎么在eth链上产生1~5的随机数

我要产生 1000 个 1~5 的数字,而且每种数字个数是不同的,怎么在链上产生合适,如果只是随机产生那么每种数字出现的频率是一样的,这样也不太好,数字 1 可能需要 800 个,而数字 5 只要 5 个,

dego空投nft的时候每个nft的等级是怎么产生的?

  • 2021-03-08 17:19
Tiny熊 - 布道者 2021-03-08 17:57

  擅长:智能合约,以太坊

产生 1~5 的数字, 可以使用 1 一个数 % 5(取模) 再加 1。

如果要更多数字落到一些数字上, 可以一些 % 2 一些 % 3 一些 % 4 等。

您需要登录后才可以回答问题,登录 或者 注册

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK