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

Re: Sorting file names randomly



On Sun, Jul 24, 2005 at 06:44:15AM +0000, Bart Schaefer wrote:
> A more efficient way might be this:
> 
>     function shuffle {
>       emulate -L zsh
>       declare -A h
>       local +h -Z 5 RANDOM=$SECONDS
>       integer i
>       # set -- $~*   # uncomment to use with noglob alias
>       for ((i=1; i <= $#; ++i)) { h[$i.$RANDOM]=$argv[i] }
>       reply=( $h )
>       print -l $reply
>     }

Is there any chance that prepending "$i." and hashing it will
decrease the randomness of the shuffle significantly?



Messages sorted by: Reverse Date, Date, Thread, Author