Skip to content

Commit

Permalink
fix(core/addr): avoid probabilistic when NodeNo is generated
Browse files Browse the repository at this point in the history
Closes #144
  • Loading branch information
loyd committed Dec 15, 2024
1 parent ab0bd16 commit e73432e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion elfo-core/src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct NodeNo(NonZeroU16);

impl NodeNo {
pub(crate) fn generate() -> Self {
Self::from_bits(random_u64().max(1) as u16).unwrap()
Self::from_bits((random_u64() as u16).max(1)).unwrap()
}

#[inline]
Expand Down Expand Up @@ -333,6 +333,13 @@ mod tests {

use super::*;

#[test]
fn node_no_generate() {
for _ in 0..1_000_000 {
NodeNo::generate();
}
}

#[test]
fn node_launch_id_generate() {
let count = 10;
Expand Down

0 comments on commit e73432e

Please sign in to comment.