🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.debian.user
Article #232

Re: Bash: check if a value is into an array

#232
From: Nicolas George
Date: Wed, 21 Oct 2026 18:50
19 lines
2969 bytes
Franco Martelli (HE12026-10-21):
> a snippet of code that provides random numbers in a specified range using a
> bash function?

man bash
/random

The answer is immediate.

By the way, it seems what you want is not just distinct elements but all
the elements too: a permutation. For that, there is a much more
efficient algorithm: swap the first element randomly with any of the
elements, then the second with any of the elements except the first,
etc.

Regards,

-- 
  Nicolas George
Technical Details
Message-ID: <NQJxT-71Ty-3@gated-at.bofh.it>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!3.eu.feeder.erje.net!feeder.erje.net!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!news.imp.ch!news.corradoroberto.it!news.servidellagleba.it!bofh.it!news.nic.it!robomod
References: <NQFND-6ZMU-9@gated-at.bofh.it> <NQG6Z-703J-7@gated-at.bofh.it> <NQJod-71PP-13@gated-at.bofh.it>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!3.eu.feeder.erje.net!feeder.erje.net!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!news.imp.ch!news.corradoroberto.it!news.servidellagleba.it!bofh.it!news.nic.it!robomod
From: Nicolas George <george@nsup.org>
Newsgroups: linux.debian.user
Subject: Re: Bash: check if a value is into an array
Date: Wed, 21 Oct 2026 20:50:01 +0200
Message-ID: <NQJxT-71Ty-3@gated-at.bofh.it>
References: <NQFND-6ZMU-9@gated-at.bofh.it> <NQG6Z-703J-7@gated-at.bofh.it> <NQJod-71PP-13@gated-at.bofh.it>
X-Mailbox-Line: From debian-user-request@lists.debian.org  Wed Oct 21 18:48:42 2026
Old-Return-Path: <george@phare.normalesup.org>
X-Amavis-Spam-Status: No, score=-4.048 tagged_above=-10000 required=5.3
 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
 HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3,
 RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001]
 autolearn=ham autolearn_force=no
X-Policyd-Weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 HELO_IP_IN_CL_SUBNET=-1.2 (check from: .normalesup. - helo: .nef.ens. - helo-domain: .ens.)  FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -4.7
X-Ens-Nef-Client: 129.199.129.80 ( name = phare.normalesup.org )
Authentication-Results: nef.ens.fr; dkim=pass
	reason="2048-bit key; unprotected key"
	header.d=nsup.org header.i=@nsup.org header.b=g6Wbx8OB;
	dkim-adsp=pass; dkim-atps=neutral
Reply-To: debian-user@lists.debian.org
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Wed, 21 Oct 2026 20:48:29 +0200 (CEST)
X-Mailing-List: <debian-user@lists.debian.org> archive/latest/832540
List-ID: <debian-user.lists.debian.org>
List-URL: <https://lists.debian.org/debian-user/>
List-Archive: https://lists.debian.org/msgid-search/atkI_Agk3vuY5vlg@phare.normalesup.org
Approved: robomod@news.nic.it
Lines: 19
Organization: linux.* mail to news gateway
Sender: robomod@news.nic.it
X-Original-Date: Wed, 21 Oct 2026 20:48:28 +0200
X-Original-Message-ID: <atkI_Agk3vuY5vlg@phare.normalesup.org>
X-Original-References: <fb4588c5-2637-4714-81e6-791a9260afbd@gmail.com>
 <20261021150743.GA21484@wooledge.org>
 <b397ac30-dbff-4822-b314-c6cc97dc0df8@gmail.com>