mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-17 01:51:00 +03:00
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:
parent
599df82049
commit
6fa6bb051c
@ -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 ))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user