# Struct proptest::test_runner::TestRng

source · `pub struct TestRng { /* private fields */ }`

## Expand description

Proptest’s random number generator.

## Implementations§

source§### impl TestRng

### impl TestRng

source#### pub fn from_seed(algorithm: RngAlgorithm, seed: &[u8]) -> Self

#### pub fn from_seed(algorithm: RngAlgorithm, seed: &[u8]) -> Self

Create 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 `seed`

is not an appropriate length for `algorithm`

.

source#### pub fn bytes_used(&self) -> Vec<u8> ⓘ

#### pub 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.

source#### pub fn deterministic_rng(algorithm: RngAlgorithm) -> Self

#### pub fn deterministic_rng(algorithm: RngAlgorithm) -> Self

Returns a `TestRng`

with 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 `bool`

which is supposed to produce `true`

50% 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 or `TestRunner::deterministic()`

avoids such
issues.

## Trait Implementations§

## Auto Trait Implementations§

### impl Freeze for TestRng

### impl RefUnwindSafe for TestRng

### impl Send for TestRng

### impl Sync for TestRng

### impl Unpin for TestRng

### impl UnwindSafe for TestRng

## Blanket Implementations§

source§### impl<T> BorrowMut<T> for Twhere
T: ?Sized,

### impl<T> BorrowMut<T> for Twhere
T: ?Sized,

source§#### fn borrow_mut(&mut self) -> &mut T

#### fn borrow_mut(&mut self) -> &mut T

source§### impl<R> Rng for R

### impl<R> Rng for R

source§#### fn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,

#### fn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,

source§#### fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,

#### fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,

source§#### fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,

#### fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,

source§#### fn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T>where
D: Distribution<T>,
Self: Sized,

#### fn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T>where
D: Distribution<T>,
Self: Sized,

source§#### fn gen_bool(&mut self, p: f64) -> bool

#### fn gen_bool(&mut self, p: f64) -> bool

`p`

of being true. Read moresource§#### fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool

#### fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool

`numerator/denominator`

of being
true. I.e. `gen_ratio(2, 3)`

has chance of 2 in 3, or about 67%, of
returning true. If `numerator == denominator`

, then the returned value
is guaranteed to be `true`

. If `numerator == 0`

, then the returned
value is guaranteed to be `false`

. Read more