std-type

RandomState — randomized default hasher builder

RandomState supplies the default hasher builder for HashMap and HashSet. It uses randomized initialization to help resist collision-heavy inputs. Keep the default for untrusted keys unless a carefully reviewed alternative is justified. No particular hash output or algorithm is a stable promise. Expected stdout (not executed): 8 Common mistake: Comparing numeric hashes from different RandomState instances or assuming randomized hashing is cryptographic authentication.

Formal Syntax & Structure

rust syntaxrust
RandomState::new() -> RandomState

Working Example

Example Snippetrust
fn main() {    use std::{collections::HashMap, hash::RandomState};    let mut m = HashMap::with_hasher(RandomState::new());    m.insert("item", 8);    println!("{}", m["item"]);}
Rust Reference