From 6fa6bb051c2b83f90dc12a64e63d1cb2b0d12c96 Mon Sep 17 00:00:00 2001 From: Pawel Jakub Dawidek Date: Sat, 6 May 2023 01:09:12 +0900 Subject: [PATCH] Simplify and optimize random_int_between(). Reviewed-by: Brian Behlendorf Signed-off-by: Pawel Jakub Dawidek Closes #14805 --- tests/zfs-tests/include/math.shlib | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/zfs-tests/include/math.shlib b/tests/zfs-tests/include/math.shlib index 38d9fecea..da1e77e5f 100644 --- a/tests/zfs-tests/include/math.shlib +++ b/tests/zfs-tests/include/math.shlib @@ -118,9 +118,7 @@ function verify_ne # # 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 @@ -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 )) }