Re: Permutations
Juho Snellman <[email protected]> Fri, 30 Jan 2004 23:44:18 +0200
| Newsgroups | gmane.comp.lang.perl.golf |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Jan 30, 2004 at 02:57:32PM -0600, J. Riley Bryant wrote:
> % perl -le 'for (1..1e5) { $i = 0; $a[$i++][$_]++ for sort { rand 2 }
> 1..8}; print "@{$_}" for @a'
[...]
> % perl -le '@_=(1..8); for (1..1e5) {$i=0; $a[$i++][$_]++ for
> @_=sort{rand 2}@_} print "@{$_}" for @a'
[...]
> I don't really understand why @_=sort{rand 2}@_ would seem
> to be more randomly distributed.
The first version is somewhat analogous to taking a sorted deck of
cards, shuffling it once, noting the distribution of the cards,
sorting it back and shuffling it again, etc. The second one is like
shuffling the cards, noting the distribution, shuffling again, etc. It
should be obvious which method will produce the better (umm...)
distribution of distributions.
--
Juho Snellman