如何在底物中生成随机数?

问题描述

大家好,有可能使用rand crate在基板上生成一个随机数吗?

因为我将其导入到Cargo.toml文件中

[dependencies.rand] 
version = '0.7.3' 

它给我以下错误

duplicate lang item in crate `std` (which `rand` depends on): `panic_impl`.
  |
  = note: the lang item is first defined in crate `sp_io` (which `frame_support` depends on)
  = note: first definition in `sp_io` loaded from /home/noone/powattem/substrate-node-template/target/release/wbuild/target/wasm32-unknown-unknown/release/deps/libsp_io-335dca76a9d63bdd.rmeta
  = note: second definition in `std` loaded from /home/noone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-023ef8617de52e0e.rlib

解决方法

节点模板包括the Randomness Collective Flip pallet,该模板实现了the Randomness trait。您似乎要导入的板条箱似乎具有union依赖性,在必须编译为Wasm的Substrate运行时中将无法使用。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...