From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, NORMAL_HTTP_TO_IP,NUMERIC_HTTP_ADDR,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 5a784147 for ; Sun, 1 Dec 2019 21:23:18 +0000 (UTC) Received: (qmail 3068 invoked by alias); 1 Dec 2019 21:23:11 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 24485 Received: (qmail 23396 invoked by uid 1010); 1 Dec 2019 21:23:11 -0000 X-Qmail-Scanner-Diagnostics: from 195-159-176-226.customer.powertech.no by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.0/25649. spamassassin: 3.4.2. Clear:RC:0(195.159.176.226):SA:0(1.0/5.0):. Processed in 1.502373 secs); 01 Dec 2019 21:23:11 -0000 X-Envelope-From: gcszu-zsh-users@m.gmane.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at m.gmane.org does not designate permitted sender hosts) X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: zsh-users@zsh.org To: zsh-users@zsh.org From: Emanuel Berg Subject: Re: shuffle array Date: Sun, 01 Dec 2019 22:22:27 +0100 Message-ID: <86v9qzpwq4.fsf@zoho.eu> References: <867e3jxtao.fsf@zoho.eu> <20191129064215.GA14095@prometheus.u-strasbg.fr> <8636e7w0w9.fsf__36104.0529723809$1575015640$gmane$org@zoho.eu> <20191201200719.anzbs27c7phgdnmm@chaz.gmail.com> Mime-Version: 1.0 Content-Type: text/plain User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Mail-Copies-To: never Cancel-Lock: sha1:7gg5uUA42ILChXtSu0lCMT1LBNA= Stephane Chazelas wrote: > You could do things like: > > array=("${(0@)$(printf '%s\0' "$array[@]" | shuf -z)[1,-2]}") It seems I always get the same shuffle for that? (1 2 3 a b c) -> (c 1 a 3 b 2) and (x y z 1 2 3) -> (3 x 1 z 2 y) - the same. Another thing, how do I use this to shuffle an array from another function? How do I send the array as a name/pointer argument, i.e. not just the value? Or how can I return the new array and set the old one's value to that? # from SC on gmane.comp.shells.zsh.user shuffle-array-2 () { local -a array array=($@) array=("${(0@)$(printf '%s\0' "$array[@]" | shuf -z)[1,-2]}") echo $array } https://dataswamp.org/~incal/conf/.zsh/shuffle -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal