From a02be13dd12b83c329b338d09509a31092ef55f5 Mon Sep 17 00:00:00 2001 From: bol-van Date: Fri, 20 Dec 2024 16:57:27 +0300 Subject: [PATCH] base.sh: support randoms in shells with 32-bit math --- common/base.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/common/base.sh b/common/base.sh index c8e4be9..0be2614 100644 --- a/common/base.sh +++ b/common/base.sh @@ -318,18 +318,27 @@ setup_md5() exists $MD5 || MD5=md5 } +setup_random() +{ + [ -n "$RCUT" ] && return + RCUT="cut -c 1-17" + # some shells can operate with 32 bit signed int + [ $((0x100000000)) = 0 ] && RCUT="cut -c 1-9" +} + random() { # $1 - min, $2 - max local r rs setup_md5 + setup_random if [ -c /dev/urandom ]; then read rs