Gen from seed
jakoschiko opened this issue · 8 comments
Many crates implement quickcheck::Arbitrary
and I was very happy that I could use these implementations in dicetest by implementing quickcheck::Gen
. Unfortunately I can't do this anymore since quickcheck 1.0.
Would it be possible to provide a function that creates a Gen
from a seed? Something like that:
impl Gen {
pub fn from_seed(seed: u64, size: usize) -> Gen {
Gen { rng: rand::rngs::SmallRng::seed_from_u64(seed), size: size }
}
}
That seems sensible to me. I think we should leave off the size parameter perhaps though. I regret that Gen's constructor has it instead of providing a set_size
method. So we'll want that when this new constructor is added.
Can I help by creating a PR?
I'm in no hurry, I'll do it within the next days.
May I suggest from_rng(rng)
too? @jakoschiko
I have a supplied random gen from the environment that I have to use.
I tried
Gen {
rng: SmallRng::from_rng(rng).unwrap(),
size: 42,
}
but got
183 | rng: SmallRng::from_rng(rng).unwrap(),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ private field
Maybe just making both fields pub
would work? Of course that depends on how settled Gen
is...
No. Because that makes rand_core
a public dependency.
@ggreif
rand_core
was recently removed from the interface, see #265. I didn't want to discuss this in this issue, I just wanted a replacement. If elegance doesn't matter, you could generate an u64
using rng
and pass it to Gen::from_seed
. I think SmallRng::from_rng
does something similar, but with more bytes.
Great, a u64
seed is perfectly adequate for my purposes. I am happy without from_rng
.