Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Permute 1..N
- X-seq: zsh-users 2934
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx>
- To: Sven Guckes <guckes@xxxxxxxxxxxxxxxxx>, ZShell Users <zsh-users@xxxxxxxxxxxxxx>
- Subject: Re: Permute 1..N
- Date: Wed, 1 Mar 2000 15:14:51 -0800
- In-reply-to: <20000301234635.A1137@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <20000301234635.A1137@xxxxxxxxxxxxxxxxxxxxxx>
On Mar 1, 11:46pm, Sven Guckes wrote:
> Subject: Permute 1..N
> What's an elegant method to let zsh generate
> a list of numbers one to N in a permutation?
>
> $ permute 10
> 5 7 3 6 1 10 2 4 8 9
function permute() {
local n
set {1..$1}
while (( $# )); do
n=$[RANDOM%#+1]
print -n "$argv[n] "
argv[n]=$1
shift
done
print
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author