The following code from this post runs in the Playground...
use rand::{SeedableRng, Rng};
use rand_pcg::Pcg32;
fn main() {
let mut rng = Pcg32::seed_from_u64(42);
for _ in 0..10 {
let x: u32 = rng.gen();
println!("{}", x);
}
}
...but has a compilation error (and some warnings) on my machine:
error[E0599]: no function or associated item named `seed_from_u64` found for struct `Lcg64Xsh32` in the current scope
--> src/main.rs:5:26
|
5 | let mut rng = Pcg32::seed_from_u64(42);
| ^^^^^^^^^^^^^ function or associated item not found in `Lcg64Xsh32`
|
= help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
1 | use rand_core::SeedableRng;
|
warning: unused import: `SeedableRng`
--> src/main.rs:1:12
|
1 | use rand::{SeedableRng, Rng};
| ^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused import: `Rng`
--> src/main.rs:1:25
|
1 | use rand::{SeedableRng, Rng};
| ^^^
Following the compiler's instructions about the error E0599 , I changed
use rand::{SeedableRng, Rng};
to
use rand::Rng;
use rand_core::SeedableRng;
and built again, this time receiving the same type of error, but for a different place in the code:
error[E0599]: no method named `gen` found for struct `Lcg64Xsh32` in the current scope
--> src/main.rs:8:26
|
8 | let x: u32 = rng.gen();
| ^^^ method not found in `Lcg64Xsh32`
|
::: /home/sjw/.cargo/registry/src/github.com-1ecc6299db9ec823/rand_pcg-0.3.0/src/pcg64.rs:34:1
|
34 | pub struct Lcg64Xsh32 {
| ---------------------
| |
| doesn't satisfy `Lcg64Xsh32: Rng`
| doesn't satisfy `Lcg64Xsh32: rand::RngCore`
|
= note: the method `gen` exists but the following trait bounds were not satisfied:
`Lcg64Xsh32: rand::RngCore`
which is required by `Lcg64Xsh32: Rng`
warning: unused import: `rand::Rng`
--> src/main.rs:1:5
|
1 | use rand::Rng;
| ^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
I can see from the compiler output that rand::Rng
is unused, and that rand_pcg::Lcg64Xsh32
requires rang::Rng
, so I imagine there is maybe something missing to link these two together.
Both the Playground and my local machine are using 1.48.0 from the Stable channel of the 2018 edition.
Thank you for any tips!