Logo

Programming-Idioms

History of Idiom 69 > diff from v30 to v31

Edit summary for version 31 by freecoder:
[Rust] Add demo

Version 30

2018-12-18, 16:14:48

Version 31

2018-12-18, 16:17:02

Idiom #69 Seed random generator

Use seed s to initialize a random generator.

If s is constant, the generator output will be the same each time the program runs. If s is based on the current value of the system clock, the generator output will be different each time.

Idiom #69 Seed random generator

Use seed s to initialize a random generator.

If s is constant, the generator output will be the same each time the program runs. If s is based on the current value of the system clock, the generator output will be different each time.

Imports
use rand::{Rng, SeedableRng, rngs::StdRng};
Imports
use rand::{Rng, SeedableRng, rngs::StdRng};
Code
let mut rng = StdRng::from_seed(s);
Code
let mut rng = StdRng::from_seed(s);
Doc URL
https://docs.rs/rand/*/rand/trait.SeedableRng.html
Doc URL
https://docs.rs/rand/*/rand/trait.SeedableRng.html
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=5cc930468067bafd57f6bc80bca789e9