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

Re: Sorting file names randomly



On Nov 18, 11:21pm, Clint Adams wrote:
} Subject: Re: Sorting file names randomly
}
} On Sun, Jul 24, 2005 at 06:44:15AM +0000, Bart Schaefer wrote:
} >       for ((i=1; i <= $#; ++i)) { h[$i.$RANDOM]=$argv[i] }
} 
} Is there any chance that prepending "$i." and hashing it will
} decrease the randomness of the shuffle significantly?

I no longer remember why I didn't just use h[$RANDOM] -- it may have
been a typo.  Looking back at the part of my message that you trimmed,
I said:

: The local RANDOM is there to force it to be zero-padded to 5 places,
: so all the hash keys are the same length; probably not essential.

But $i is not padded, so if that's prepended the hash keys aren't all
the same length any more, which is why I wonder whether it's meant to
be there at all.

However, I suspect the randomness might be reduced for large numbers
of arguments whether or not $i is prepended, because within each hash
bucket the values are in a list in the order they were added to that
bucket.



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