diff options
author | Ryan Moeller <[email protected]> | 2020-01-08 12:08:30 -0500 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2020-01-08 09:08:30 -0800 |
commit | f8d55b95a5ed825d4fb50cc8e0e03edf25bd44e3 (patch) | |
tree | 19915594bbce237365aa2b1964801862fe32f67e /tests/zfs-tests/include/math.shlib | |
parent | 028e3b3b1a8d15a9ab5a0c925ca32fd3851cfa36 (diff) |
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 <[email protected]>
Reviewed-by: Kjeld Schouten <[email protected]>
Reviewed-by: Igor Kozhukhov <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: George Melikov <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes #9820
Diffstat (limited to 'tests/zfs-tests/include/math.shlib')
-rw-r--r-- | tests/zfs-tests/include/math.shlib | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/zfs-tests/include/math.shlib b/tests/zfs-tests/include/math.shlib index 0c3508ec2..692a2a45b 100644 --- a/tests/zfs-tests/include/math.shlib +++ b/tests/zfs-tests/include/math.shlib @@ -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 +} |