rand::SeedableRng - Rust
Description: API documentation for the Rust `SeedableRng` trait in crate `rand`.
Keywords: rust, rustlang, rust-lang, SeedableRng

# Trait rand::SeedableRng [−] [src]

    pub trait SeedableRng<Seed>: Rng {
        fn reseed(&mut self, _: Seed);
        fn from_seed(seed: Seed) -> Self;
    }

A random number generator that can be explicitly seeded to produce the same stream of randomness multiple times.

## Required Methods

### `fn reseed(&mut self, _: Seed)`

Reseed an RNG with the given seed.

# Example

    use rand::{Rng, SeedableRng, StdRng};

    let seed: &[_] = &[1, 2, 3, 4];
    let mut rng: StdRng = SeedableRng::from_seed(seed);
    println!("{}", rng.gen::<f64>());
    rng.reseed(&[5, 6, 7, 8]);
    println!("{}", rng.gen::<f64>());

### `fn from_seed(seed: Seed) -> Self`

Create a new RNG with the given seed.

# Example

    use rand::{Rng, SeedableRng, StdRng};

    let seed: &[_] = &[1, 2, 3, 4];
    let mut rng: StdRng = SeedableRng::from_seed(seed);
    println!("{}", rng.gen::<f64>());

## Implementors

- `impl<'a> SeedableRng<&'a [u32]> for IsaacRng`
- `impl<'a> SeedableRng<&'a [u64]> for Isaac64Rng`
- `impl<'a> SeedableRng<&'a [u32]> for ChaChaRng`
- `impl<S, R: SeedableRng<S>, Rsdr: Reseeder<R> + Default> SeedableRng<(Rsdr, S)> for ReseedingRng<R, Rsdr>`
- `impl SeedableRng<[u32; 4]> for XorShiftRng`
- `impl<'a> SeedableRng<&'a [usize]> for StdRng`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)