Skip to content

Commit

Permalink
chore: fix rng warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
reubeno committed Feb 3, 2025
1 parent 74c8527 commit f7ad900
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions brush-core/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1564,15 +1564,15 @@ fn repeated_char_str(c: char, count: usize) -> String {
}

fn get_random_value(_shell: &Shell) -> ShellValue {
let mut rng = rand::thread_rng();
let num = rng.gen_range(0..32768);
let mut rng = rand::rng();
let num = rng.random_range(0..32768);
let str = num.to_string();
str.into()
}

fn get_srandom_value(_shell: &Shell) -> ShellValue {
let mut rng = rand::thread_rng();
let num: u32 = rng.gen();
let mut rng = rand::rng();
let num: u32 = rng.random();
let str = num.to_string();
str.into()
}
16 changes: 16 additions & 0 deletions brush-shell/tests/cases/well_known_vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ cases:
echo "LINENO: $LINENO"
done
- name: "RANDOM"
stdin: |
first=${RANDOM}
second=${RANDOM}
[[ $first != $second ]] && echo "Confirmed RANDOM at least isn't static"
[[ $first -ge 0 && $first -lt 32768 ]] && echo "RANDOM value is within expected range"
[[ $second -ge 0 && $second -lt 32768 ]] && echo "RANDOM value is within expected range"
- name: "SHELLOPTS"
stdin: |
echo "SHELLOPTS: $SHELLOPTS"
Expand All @@ -135,3 +144,10 @@ cases:
echo "SHLVL: $SHLVL"
bash -c 'echo "bash SHLVL: $SHLVL"'
$0 -c 'echo "nested SHLVL: $SHLVL"'
- name: "SRANDOM"
stdin: |
first=${SRANDOM}
second=${SRANDOM}
[[ $first != $second ]] && echo "Confirmed SRANDOM at least isn't static"

0 comments on commit f7ad900

Please sign in to comment.