diff --git a/keyfork-mnemonic-generate/src/main.rs b/keyfork-mnemonic-generate/src/main.rs index ec31d2c..de974ad 100644 --- a/keyfork-mnemonic-generate/src/main.rs +++ b/keyfork-mnemonic-generate/src/main.rs @@ -94,7 +94,7 @@ fn ensure_offline() { // TODO: Can a Mnemonic be formatted using a wordlist, without allocating or without storing the // entire word list? struct Mnemonic { - words: Vec, + pub words: Vec, wordlist: Vec, } @@ -232,4 +232,20 @@ mod tests { } Ok(()) } + + #[test] + fn count_to_get_duplicate_words() { + let mut count = 0.; + let mut random_handle = File::open("/dev/urandom").unwrap(); + let entropy = &mut [0u8; 256 / 8]; + for _ in 0..100_000 { + random_handle.read_exact(&mut entropy[..]).unwrap(); + let mut mnemonic = Mnemonic::from_entropy(&entropy[..256 / 8]).unwrap(); + mnemonic.words.dedup(); + if mnemonic.words.len() != 24 { + count += 1.; + } + } + panic!("counts: {count} {}", count / 100_000.) + } }