Use mersenne_twister: impossible to import trait?

I have an issue with importing the proper rand trait for the mersenne_twister crate:

I added mersenne_twister and rand

cargo add rand
cargo add mersenne_twister

Here is the code I have in a

extern crate mersenne_twister;
extern crate rand;
use mersenne_twister::MersenneTwister;
use rand::{Rng, RngCore, SeedableRng};

fn main() {
    // Get a seed somehow.
    let seed: u64 = 0x123456789abcdef;
    // Create the default RNG.
    let mut rng: MersenneTwister = SeedableRng::from_seed(seed); <- issue 1
    rng.gen(); <- issue 2


which is a copy paste from the official doc.

The issues:

the trait bound `MT19937_64: SeedableRng` is not satisfied
the following other types implement trait `SeedableRng`:


the method `gen` exists for struct `MT19937_64`, but its trait bounds were not satisfied
the following trait bounds were not satisfied:
`MT19937_64: RngCore`
which is required by `MT19937_64: Rng`
items from traits can only be used if the trait is in scope, 1): doesn't satisfy `MT19937_64: RngCore`, 1): doesn't satisfy `MT19937_64: Rng`, 1): the following trait is implemented but not in scope; perhaps add a `use` for it:: `use rand::Rng;

I already have rand::* imported so I don't know what to do now.

Normally, when importing a trait, everything solves by itself, but not here. So there is something I missed.

Any insights?

The mersenne_twister crate (being fairly old) only works with an older version of the rand crate. Admitted, Rust's error messages in this case (trait implemented only for a different version of that crate) are often a bit too confusing.

1 Like

Ok, I will swtich the crate then.

Thanks for the really quick answer :+1:

Looks like rand version 0.4.6 is the latest that mersenne_twister would support.

1 Like

You are right, I ended using the Xoshiro family from the rand_xoshiro crate.

I couldn't be happier with the perf.

I still struggle there and there with some crates but I really enjoy this language experience + great community.

Thanks guys, really

1 Like