In this post, we will see how to resolve How do I create a Strategy that generates a value in a given range in proptest?
Question:I want to create a
u32values less than
1000000efficiently and uniformly. The only two ways that I know to do this are to use
any::<u32>()and then do one of the following:
prop_filterto filter out values greater than or equal to
prop_mapto convert the values greater than or equal to
1000000to values less than
1000000using 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
Best Answer:Just use a
Range, as their tutorial states:
0..100i32 is a strategy to generate i32s between 0, inclusive, and 100, exclusive
so the strategy for numbers up to
If you have better answer, please add a comment about this, thank you!