Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Permute 1..N



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