Skip to content

Commit

Permalink
Simplify and optimize random_int_between().
Browse files Browse the repository at this point in the history
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Pawel Jakub Dawidek <pawel@dawidek.net>
Closes openzfs#14805
  • Loading branch information
pjd authored May 5, 2023
1 parent 599df82 commit 6fa6bb0
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions tests/zfs-tests/include/math.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ function verify_ne # <a> <b> <type>

# A simple function to get a random number between two bounds (inclusive)
#
# Probably not the most efficient for large ranges, but it's okay.
#
# Note since we're using $RANDOM, 32767 is the largest number we
# Note since we're using $RANDOM, $min+32767 is the largest number we
# can accept as the upper bound.
#
# $1 lower bound
Expand All @@ -129,11 +127,6 @@ function random_int_between
{
typeset -i min=$1
typeset -i max=$2
typeset -i rand=0

while [[ $rand -lt $min ]] ; do
rand=$(( $RANDOM % $max + 1))
done

echo $rand
echo $(( (RANDOM % (max - min + 1)) + min ))
}

0 comments on commit 6fa6bb0

Please sign in to comment.