Skip to content

Commit

Permalink
feat: simplify getrandom call (#325)
Browse files Browse the repository at this point in the history
New in getrandom 0.3, we can now get numbers directly. On some systems,
this'll use special CPU instructions and can be instantaneous. We're not
using them for crypto, so I'm not going to be picky.
  • Loading branch information
Stebalien authored Feb 15, 2025
1 parent 1e5059f commit 35e0629
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ pub fn create_helper<R>(
any(windows, unix, target_os = "redox", target_os = "wasi")
))]
if i == 3 {
let mut seed = [0u8; 8];
if getrandom::fill(&mut seed).is_ok() {
rng.seed(u64::from_ne_bytes(seed));
if let Ok(seed) = getrandom::u64() {
rng.seed(seed);
}
}
let path = base.join(tmpname(&mut rng, prefix, suffix, random_len));
Expand Down

0 comments on commit 35e0629

Please sign in to comment.