Ben Chuanlong Du's Blog

And let it direct your passion with reason.

Seed Many RNGs in Rust

There are different ways to seed many RNGs (for parallel RNGs). Below summarizes 3 popular ways. Seeding RNGs using std::collections::hash_map::RandomState or rand::thread_rng is preferred.

Seed Using System Time

use std::time::{SystemTime, UNIX_EPOCH};
use rand::SmallRng;

fn main () {
    let seed = SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .unwrap()
        .as_nanos …