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, 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 d1485df9 for ; Fri, 29 Nov 2019 13:39:13 +0000 (UTC) Received: (qmail 2577 invoked by alias); 29 Nov 2019 13:39:04 -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: 24482 Received: (qmail 15853 invoked by uid 1010); 29 Nov 2019 13:39:04 -0000 X-Qmail-Scanner-Diagnostics: from thumb.scru.org by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.0/25642. spamassassin: 3.4.2. Clear:RC:0(104.200.20.71):SA:0(-1.1/5.0):. Processed in 2.494821 secs); 29 Nov 2019 13:39:04 -0000 X-Envelope-From: clint@zsh.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: neutral (ns1.primenet.com.au: 104.200.20.71 is neither permitted nor denied by SPF record at zsh.org) Date: Fri, 29 Nov 2019 13:38:24 +0000 From: Clint Adams To: zsh-users@zsh.org Subject: Re: shuffle array Message-ID: <20191129133824.GA25621@scru.org> References: <867e3jxtao.fsf@zoho.eu> <20191129064215.GA14095@prometheus.u-strasbg.fr> <8636e7w0w9.fsf@zoho.eu> <20191129084304.GA20296@prometheus.u-strasbg.fr> <86r21rukvv.fsf@zoho.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <86r21rukvv.fsf@zoho.eu> User-Agent: Mutt/1.10.1 (2018-07-13) On Fri, Nov 29, 2019 at 09:50:12AM +0100, Emanuel Berg wrote: > $ local -a arg_array > $ arg_array=(1 2 3 a b c) > $ print -l $arg_array | shuf | read -A new_array > $ echo $new_array > 1 > > doesn't work, just one element... `read` only reads one line. I don't remember where this came from, but I've been using shuffle() { declare -A h local +h -Z 5 RANDOM=$EPOCHSECONDS integer i for ((i=1; i <= $#; ++i)) { h[$i.$RANDOM]=$argv[i] } reply=( $h ) }