mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
ZTS: Eliminate functions named 'random'
The name overlaps with a command needed by FreeBSD. There is also no sense having two 'random' functions that do nearly the same thing, so consolidate to just the more general one and name it 'random_int_between'. Reviewed-by: John Kennedy <john.kennedy@delphix.com> Reviewed-by: Kjeld Schouten <kjeld@schouten-lebbing.nl> Reviewed-by: Igor Kozhukhov <igor@dilos.org> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: George Melikov <mail@gmelikov.ru> Signed-off-by: Ryan Moeller <ryan@ixsystems.com> Closes #9820
This commit is contained in:
committed by
Brian Behlendorf
parent
028e3b3b1a
commit
f8d55b95a5
@@ -3349,15 +3349,6 @@ function get_min
|
||||
echo $min
|
||||
}
|
||||
|
||||
#
|
||||
# Generate a random number between 1 and the argument.
|
||||
#
|
||||
function random
|
||||
{
|
||||
typeset max=$1
|
||||
echo $(( ($RANDOM % $max) + 1 ))
|
||||
}
|
||||
|
||||
# Write data that can be compressed into a directory
|
||||
function write_compressible
|
||||
{
|
||||
|
||||
@@ -119,3 +119,25 @@ function verify_ne # <a> <b> <type>
|
||||
log_fail "Compared $type should be not equal: $a == $b"
|
||||
fi
|
||||
}
|
||||
|
||||
# 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
|
||||
# can accept as the upper bound.
|
||||
#
|
||||
# $1 lower bound
|
||||
# $2 upper bound
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user