Struct TestRng
pub struct TestRng { /* private fields */ }
Proptest's random number generator.
Implementations
impl TestRng
fn from_seed(algorithm: RngAlgorithm, seed: &[u8]) -> SelfCreate a new RNG with the given algorithm and seed.
Any RNG created with the same algorithm-seed pair will produce the same sequence of values on all systems and all supporting versions of proptest.
Panics
Panics if
seedis not an appropriate length foralgorithm.fn bytes_used(&self) -> Vec<u8>Dumps the bytes obtained from the RNG so far (only works if the RNG is set to
Recorder).Panics
Panics if this RNG does not capture generated data.
fn deterministic_rng(algorithm: RngAlgorithm) -> SelfReturns a
TestRngwith a particular hard-coded seed.The seed value will always be the same for a particular version of Proptest and algorithm, but may change across releases.
This is useful for testing things like strategy implementations without risking getting "unlucky" RNGs which deviate from average behaviour enough to cause spurious failures. For example, a strategy for
boolwhich is supposed to producetrue50% of the time might have a test which checks that the distribution is "close enough" to 50%. If every test run starts with a different RNG, occasionally there will be spurious test failures when the RNG happens to produce a very skewed distribution. Using this orTestRunner::deterministic()avoids such issues.
Trait Implementations
impl Clone for TestRng
fn clone(&self) -> Self
impl Debug for TestRng
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl TryRng for TestRng
type Error = never;fn try_next_u32(&mut self) -> Result<u32, Self::Error>fn try_next_u64(&mut self) -> Result<u64, Self::Error>fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error>