# StepRng in rand::rngs::mock - Rust
A simple implementation of `RngCore` for testing purposes.
Keywords: rust, rustlang, rust-lang, StepRng

# Struct rand::rngs::mock::StepRng

source · [−]

    pub struct StepRng { /* private fields */ }

Expand description

A simple implementation of `RngCore` for testing purposes.

This generates an arithmetic sequence (i.e. adds a constant each step) over a `u64` number, using wrapping arithmetic. If the increment is 0 the generator yields a constant.

    use rand::Rng;
    use rand::rngs::mock::StepRng;

    let mut my_rng = StepRng::new(2, 1);
    let sample: [u64; 3] = my_rng.gen();
    assert_eq!(sample, [2, 3, 4]);

## Implementations

source

### impl StepRng

source

#### pub fn new(initial: u64, increment: u64) -> Self

Create a `StepRng`, yielding an arithmetic sequence starting with `initial` and incremented by `increment` each time.

## Trait Implementations

source

### impl Clone for StepRng

source

#### fn clone(&self) -> StepRng

Returns a copy of the value. Read more

1.0.0 · source

#### fn clone_from(&mut self, source: &Self)

Performs copy-assignment from `source`. Read more

source

### impl Debug for StepRng

source

#### fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

source

### impl PartialEq<StepRng> for StepRng

source

#### fn eq(&self, other: &StepRng) -> bool

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

source

#### fn ne(&self, other: &StepRng) -> bool

This method tests for `!=`.

source

### impl RngCore for StepRng

source

#### fn next_u32(&mut self) -> u32

Return the next random `u32`. Read more

source

#### fn next_u64(&mut self) -> u64

Return the next random `u64`. Read more

source

#### fn fill_bytes(&mut self, dest: &mut [ u8 ])

Fill `dest` with random data. Read more

source

#### fn try_fill_bytes(&mut self, dest: &mut [ u8 ]) -> Result<(), Error>

Fill `dest` entirely with random data. Read more

source

### impl Eq for StepRng

source

### impl StructuralEq for StepRng

source

### impl StructuralPartialEq for StepRng

## Auto Trait Implementations

### impl RefUnwindSafe for StepRng

### impl Send for StepRng

### impl Sync for StepRng

### impl Unpin for StepRng

### impl UnwindSafe for StepRng

## Blanket Implementations

source

### impl<T> Any for T where
T: 'static + ?Sized,

source

#### fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more

source

### impl<T> Borrow<T> for T where
T: ?Sized,

const: unstable · source

#### fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more

source

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

const: unstable · source

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

Mutably borrows from an owned value. Read more

source

### impl<T> From<T> for T

const: unstable · source

#### fn from(t: T) -> T

Returns the argument unchanged.

source

### impl<T, U> Into<U> for T where
U: From<T>,

const: unstable · source

#### fn into(self) -> U

Calls `U::from(self)`.

That is, this conversion is whatever the implementation of `From<T> for U` chooses to do.

source

### impl<T> ToOwned for T where
T: Clone,

#### type Owned = T

The resulting type after obtaining ownership.

source

#### fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more

source

#### fn clone_into(&self, target: &mut T)

🔬 This is a nightly-only experimental API. (`toowned_clone_into`)

Uses borrowed data to replace owned data, usually by cloning. Read more

source

### impl<T, U> TryFrom<U> for T where
U: Into<T>,

#### type Error = Infallible

The type returned in the event of a conversion error.

const: unstable · source

#### fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.

source

### impl<T, U> TryInto<U> for T where
U: TryFrom<T>,

#### type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

const: unstable · source

#### fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

source

### impl<V, T> VZip<V> for T where
V: MultiLane<T>,

source

#### fn vzip(self) -> V