On Tue, 9 Apr 2002 [EMAIL PROTECTED] wrote: > On Tue, Apr 09, 2002 at 01:49:01PM +0300, Ilmari Karonen wrote: > > On Fri, 5 Apr 2002 [EMAIL PROTECTED] wrote: > > > > > > sub shuffle { > > > for (my $i = @_; $i;) { > > > my $j = rand $i --; > > > @_ [$i => $j] = @_ [$j => $i] > > > } > > > @_; > > > } > > > > It doesn't, unfortunately, allow for the idiom one expects from a > > copy-and-shuffle function, namely > > > > my @shuffled = shuffle @original; > > It allows for: > > my @shuffled = shuffle 1 .. 10;
Not very consistently, though: my @shuffled = shuffle 'A',2,3,4,5,6,7,8,9,10,'J','Q','K'; Modification of a read-only value attempted at - line 4. > > =pod > > > > Alternatively, you may use this function, which shuffles its arguments > > in place. The algorithm is known as a Fisher-Yates shuffle, and can be > > proven to produce a uniform distribution of permutations, provided that > > the random number generator is sufficiently random. > > I do think it needs a reference to Knuth [1]. Or to the original publication > of Fisher and Yates [2]. > > [1] D. E. Knuth: I<The Art of Computer Programming>, Volume 2, > Third edition. Section 3.4.2, Algorithm P, pp 145. Reading: > Addison-Wesley, 1997. ISBN: 0-201-89684-2. > > [2] R. A. Fisher and F. Yates: I<Statistical Tables>. London, 1938. > Example 12. So, how _does_ one properly mark that up in POD? There are no real footnotes, and embedding the entire reference in the text would mess up the already strained flow of the paragraph. Hmm... :-( -- Ilmari Karonen - http://www.sci.fi/~iltzu/ "TIMTOWTDI often means there is more than one really bad way to do it." -- after Tim Cuffel in comp.lang.perl.misc