Open nbraud opened 3 years ago
Seems related to #267
Yes. The plan is to make a seed available, and then you should be able to materialize any RNG from that.
This really hurts the ability to write good Arbitrary impls for complicated data. I'm sure there are lots of examples, but my use case can be reduced to just a vector of vectors, Vec<Vec<u32>>
. To make sure I sample the data properly I want to generate both tall skinny arrays and short wide ones. This means that the size parameter must be divided randomly into two factors in the arbitrary
method, which requires a bounded random float.
If the issue with gen_range
is that it exposes rand
types, could I propose simply adding a public method Gen::gen_uniform(&mut self) -> f32
which generates a uniformly distributed float in the unit interval? That should satisfy most needs.
Is there a known plan to make this work that would be followed by a first time contributor?
Perhaps a bit hacky, but the workaround I ended up using was:
pub fn range(gen: &mut Gen, range: Range<u64>) -> u64 {
u64::arbitrary(gen) % (range.end - range.start) + range.start
}
I noticed when trying to update a project to
quickcheck
1.x, thatGen
is now an opaque struct and users implementingArbitrary
can only useGen::choose
to get randomness. This isn't sufficient in some usecases, which were previously served by usingGen
'sRng
methods: for instance, in uutils'factor
I need to draw integers from large ranges known at runtime, to generate integers of known factorization:(Technically, I could repeatedly use
gen.choose(&[0, 1])
to draw individual, random bits, but this would be beyond silly)