Skip to content

Commit

Permalink
fix #51: strings from rnd_node_name now always start with a letter to…
Browse files Browse the repository at this point in the history
… pass is_valid_node_name test
  • Loading branch information
gh0st42 committed Nov 22, 2023
1 parent 11622a7 commit f6b0e91
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions core/dtn7/src/dtnconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,20 @@ pub struct DtnConfig {
}

pub fn rnd_node_name() -> String {
thread_rng()
.sample_iter(&Alphanumeric)
.take(10)
.map(char::from)
.collect()
// generate a random node name starting with a character
let mut rng = thread_rng();
let mut result_str = String::new();

// Get a random letter
let first_char = rng.gen_range(b'a'..=b'z') as char;
result_str.push(first_char);

// Get 9 more random characters
for _ in 0..9 {
let next_char = thread_rng().sample_iter(&Alphanumeric).next().unwrap() as char;
result_str.push(next_char);
}
result_str
}

impl From<PathBuf> for DtnConfig {
Expand Down

0 comments on commit f6b0e91

Please sign in to comment.