nimble_ninja
nimble_ninja

Reputation: 373

How do I create a Strategy that generates a value in a given range in proptest?

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:

Is there any better way to do this, perhaps by using proptest::prelude::Rng::gen_range() somehow?

Upvotes: 1

Views: 960

Answers (1)

cafce25
cafce25

Reputation: 27539

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 1_000_000 is 0u32..1_000_000

Upvotes: 1

Related Questions