From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 828B8158287 for ; Tue, 13 May 2025 00:30:16 +0000 (UTC) Received: from lists.gentoo.org (bobolink.gentoo.org [140.211.166.189]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: relay-lists.gentoo.org@gentoo.org) by smtp.gentoo.org (Postfix) with ESMTPSA id 6DCE1343590 for ; Tue, 13 May 2025 00:30:16 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id 9D74E11036D; Tue, 13 May 2025 00:30:13 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bobolink.gentoo.org (Postfix) with ESMTPS id 93C7811036D for ; Tue, 13 May 2025 00:30:13 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 462F83433EE for ; Tue, 13 May 2025 00:30:13 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 9BF0D1E64 for ; Tue, 13 May 2025 00:30:11 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1730289758.43266e0ea45a6f9349e496ede4a8c6deaa9a611f.sam@gentoo> Subject: [gentoo-commits] proj/gentoo-functions:master commit in: / X-VCS-Repository: proj/gentoo-functions X-VCS-Files: functions.sh X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 43266e0ea45a6f9349e496ede4a8c6deaa9a611f X-VCS-Branch: master Date: Tue, 13 May 2025 00:30:11 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: f83652e5-6e99-432e-9b2d-85d1e845b985 X-Archives-Hash: cfbafb9f19a6d3d8d8eeeb600945cd1e commit: 43266e0ea45a6f9349e496ede4a8c6deaa9a611f Author: Kerin Millar plushkava net> AuthorDate: Wed Oct 30 12:02:38 2024 +0000 Commit: Sam James gentoo org> CommitDate: Wed Oct 30 12:02:38 2024 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=43266e0e Simplify the detection of SRANDOM in bash Though undocumented, bash is programmed to discard random numbers that are equal to whichever one was last generated. Hence, it is needless to ever compare two consecutive expansions of SRANDOM more than once. Signed-off-by: Kerin Millar plushkava.net> functions.sh | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/functions.sh b/functions.sh index 2414612..ec0df2d 100644 --- a/functions.sh +++ b/functions.sh @@ -586,21 +586,12 @@ quote_args() # srandom() { + # The SRANDOM variable was introduced by bash 5.1. Check for at least + # 5.0 before comparing two expansions thereof. Doing so is safe because + # bash discards numbers that are equal to whicever was last generated. + # # shellcheck disable=3028 - _has_srandom() - { - # The SRANDOM variable was introduced by bash 5.1. Check for at - # least 5.0, letting the alternate branch confirm its efficacy. - if [ "${BASH_VERSINFO-0}" -lt 5 ]; then - false - else - for _ in 1 2 3; do - test "${SRANDOM}" != "${SRANDOM}" && break - done - fi - } - - if _has_srandom; then + if [ "${BASH_VERSINFO-0}" -ge 5 ] && [ "${SRANDOM}" != "${SRANDOM}" ]; then srandom() { printf '%d\n' "$(( SRANDOM >> 1 ))" @@ -650,7 +641,6 @@ srandom() return 1 fi - unset -f _has_srandom srandom }