Simplify and optimize random_int_between().

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Pawel Jakub Dawidek <pawel@dawidek.net>
Closes #14805
This commit is contained in:
Pawel Jakub Dawidek 2023-05-06 01:09:12 +09:00 committed by GitHub
parent 599df82049
commit 6fa6bb051c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
@ -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 ))
}