I want to create a Strategy that generates u32 values less than 1000000 efficiently and uniformly. The only two ways that I know to do this are to use any::<u32>() and then do one of the following:
- use
prop_filterto filter out values greater than or equal to1000000 - use
prop_mapto convert the values greater than or equal to1000000to values less than1000000using the modulus operator (i.e..prop_map(|x|x % 1000000)). However, this would not provide a uniform sample, and it seems a bit clunky.
Is there any better way to do this, perhaps by using proptest::prelude::Rng::gen_range() somehow?
Just use a
Range, as their tutorial states:so the strategy for numbers up to
1_000_000is0u32..1_000_000