🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.debian.user
Article #253

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

#253
From: CGS
Date: Thu, 22 Oct 2026 15:40
20 lines
3066 bytes
On 2026-10-21, Greg Wooledge <greg@wooledge.org> wrote:
> On Wed, Oct 21, 2026 at 20:48:28 +0200, Nicolas George wrote:
>> 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.
>
> I didn't get that impression from his code, but if he really does want
> his playlist to be the same size, or nearly the same size, as his
> full library of selections, then shuffling the array is the way to go
> for sure.
>
> You don't want to be in a situation where you're generating random
> numbers waiting for that last song out of 10,000 songs to be chosen.
>

If I select random on a finite song playlist, I wouldn't want the same song
playing twice; this would require an algorithm that would deselect songs that
have already been chosen. Maybe your code accounted for that (or not).
Technical Details
Message-ID: <NR33A-7cWF-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!fu-berlin.de!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> <NQJxT-71Ty-3@gated-at.bofh.it> <NQJRf-729Y-7@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!fu-berlin.de!news.servidellagleba.it!bofh.it!news.nic.it!robomod
From: CGS <etphonehomefrance@gmail.com>
Newsgroups: linux.debian.user
Subject: Re: Bash: check if a value is into an array
Date: Thu, 22 Oct 2026 17:40:02 +0200
Message-ID: <NR33A-7cWF-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> <NQJxT-71Ty-3@gated-at.bofh.it> <NQJRf-729Y-7@gated-at.bofh.it>
X-Original-To: debian-user@lists.debian.org
X-Mailbox-Line: From debian-user-request@lists.debian.org  Thu Oct 22 15:35:28 2026
Old-Return-Path: <gldu-debian-user-2@m.gmane-mx.org>
X-Amavis-Spam-Status: No, score=0.253 tagged_above=-10000 required=5.3
 tests=[BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1,
 FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
 HEADER_FROM_DIFFERENT_DOMAINS=0.25, NML_ADSP_CUSTOM_MED=0.9]
 autolearn=no autolearn_force=no
X-Policyd-Weight: using cached result; rate: -4.6
X-Injected-Via-Gmane: http://gmane.org/
User-Agent: slrn/1.0.3 (Linux)
X-Mailing-List: <debian-user@lists.debian.org> archive/latest/832563
List-ID: <debian-user.lists.debian.org>
List-URL: <https://lists.debian.org/debian-user/>
List-Archive: https://lists.debian.org/msgid-search/slrn11dkb93.1hg.etphonehomefrance@einstein.home.arpa
Approved: robomod@news.nic.it
Lines: 20
Organization: linux.* mail to news gateway
Sender: robomod@news.nic.it
X-Original-Date: Thu, 22 Oct 2026 15:34:59 -0000 (UTC)
X-Original-Message-ID: <slrn11dkb93.1hg.etphonehomefrance@einstein.home.arpa>
X-Original-References: <fb4588c5-2637-4714-81e6-791a9260afbd@gmail.com>
 <20261021150743.GA21484@wooledge.org>
 <b397ac30-dbff-4822-b314-c6cc97dc0df8@gmail.com>
 <atkI_Agk3vuY5vlg@phare.normalesup.org>
 <20261021190728.GB28455@wooledge.org>