Logo

Programming-Idioms

History of Idiom 69 > diff from v38 to v39

Edit summary for version 39 by ffleader:
[Rust] The previous version needs the seed as an array. Work, but overly complicated. Change to only use a number as the seed.

Version 38

2020-10-08, 12:44:14

Version 39

2020-10-29, 22:23:10

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.

Variables
s
Variables
s
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::seed_from_u64(s);
Doc URL
https://docs.rs/rand/*/rand/trait.SeedableRng.html
Doc URL
https://docs.rs/rand/0.7.3/rand/trait.SeedableRng.html#method.seed_from_u64
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=5cc930468067bafd57f6bc80bca789e9
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=ee7b5fca5f838523e3f5023b3935952b