zsh-users
 help / color / mirror / Atom feed
From: Clint Adams <clint@zsh.org>
To: zsh-users@zsh.org
Subject: Re: shuffle array
Date: Fri, 29 Nov 2019 13:38:24 +0000
Message-ID: <20191129133824.GA25621@scru.org> (raw)
In-Reply-To: <86r21rukvv.fsf@zoho.eu>

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 )
}

  reply	other threads:[~2019-11-29 13:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-29  3:20 Emanuel Berg
2019-11-29  6:42 ` Marc Chantreux
2019-11-29  8:19   ` Emanuel Berg
2019-11-29  8:43     ` Marc Chantreux
2019-11-29  8:50       ` Emanuel Berg
2019-11-29 13:38         ` Clint Adams [this message]
     [not found]   ` <8636e7w0w9.fsf__36104.0529723809$1575015640$gmane$org@zoho.eu>
2019-12-01 20:07     ` Stephane Chazelas
2019-12-01 21:22       ` Emanuel Berg
2019-12-01 21:25         ` Emanuel Berg
2019-12-01 23:46         ` Daniel Shahaf
2019-12-02  4:10           ` Emanuel Berg
2019-12-01 23:38       ` Daniel Shahaf
     [not found]       ` <20191201233848.7selcpkvenlu65px__33142.5388505281$1575243619$gmane$org@tarpaulin.shahaf.local2>
2019-12-02 14:14         ` Stephane Chazelas
2019-12-02 14:29           ` Roman Perepelitsa
2019-11-29  8:44 ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191129133824.GA25621@scru.org \
    --to=clint@zsh.org \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

zsh-users

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-users

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-users zsh-users/ http://inbox.vuxu.org/zsh-users \
		zsh-users@zsh.org
	public-inbox-index zsh-users

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git