找不到 ChaCha20Rng from_entropy() 函数或关联项
ChaCha20Rng from_entropy() function or associated item not found
我正在试验 Rust 中的随机数生成器(我是 Rust 初学者),但我无法解决以下问题:
rust rand book 包含以下代码片段:
use rand::prelude::*;
use rand_chacha::ChaCha20Rng;
let rng = ChaCha20Rng::from_entropy();
请注意,getrandom
功能需要在 crate rand_core
上启用(我正在这样做:rand_core = { version = "0.5", features = ["getrandom"] }
)。但是我收到以下错误:no function or associated item named 'from_entropy' found for struct 'rand_chacha::ChaCha20Rng' in the current scope
。我希望有人能为我指明正确的方向,让我了解如何让这段代码正常工作。
特征方法 SeedableRng::from_entropy
在 rand_core
版本 0.6 中添加,在 rand_core
版本 0.5 中不存在。
您需要更改 Cargo.toml
的 [dependencies]
部分以请求:
rand_core
0.6 或更高版本,以及
rand_chacha
版本 0.3 或更高版本,因此从 rand_chacha
到 rand_core
的依赖项与该版本匹配,因为 Cargo 认为 0.6.* 与 0.5.*.
我正在试验 Rust 中的随机数生成器(我是 Rust 初学者),但我无法解决以下问题: rust rand book 包含以下代码片段:
use rand::prelude::*;
use rand_chacha::ChaCha20Rng;
let rng = ChaCha20Rng::from_entropy();
请注意,getrandom
功能需要在 crate rand_core
上启用(我正在这样做:rand_core = { version = "0.5", features = ["getrandom"] }
)。但是我收到以下错误:no function or associated item named 'from_entropy' found for struct 'rand_chacha::ChaCha20Rng' in the current scope
。我希望有人能为我指明正确的方向,让我了解如何让这段代码正常工作。
特征方法 SeedableRng::from_entropy
在 rand_core
版本 0.6 中添加,在 rand_core
版本 0.5 中不存在。
您需要更改 Cargo.toml
的 [dependencies]
部分以请求:
rand_core
0.6 或更高版本,以及rand_chacha
版本 0.3 或更高版本,因此从rand_chacha
到rand_core
的依赖项与该版本匹配,因为 Cargo 认为 0.6.* 与 0.5.*.