Skip to main content

random_hex_string

Function random_hex_string 

Source
pub fn random_hex_string(len: usize) -> Result<String>
Available on crate feature tier3 only.
Expand description

Generate a cryptographically-secure lowercase hex string (0-9, a-f) of exactly len characters.

Distinct from random_hex: random_hex takes a byte count and returns bytes * 2 hex characters; this function takes a character count directly. Both produce identical entropy per character but accept different argument units.

§Example

use mod_rand::tier3;
let s = tier3::random_hex_string(40)?;
assert_eq!(s.len(), 40);