Change 11855 by jhi@alpha on 2001/09/04 12:04:16
Update the FAQ now that Scalar-List-Utils 1.03 has shuffle().
Affected files ...
... //depot/perl/pod/perlfaq4.pod#44 edit
Differences ...
==== //depot/perl/pod/perlfaq4.pod#44 (text) ====
Index: perl/pod/perlfaq4.pod
--- perl/pod/perlfaq4.pod.~1~ Tue Sep 4 06:15:05 2001
+++ perl/pod/perlfaq4.pod Tue Sep 4 06:15:05 2001
@@ -1198,7 +1198,14 @@
=head2 How do I shuffle an array randomly?
-Use this:
+If you either have Perl 5.8.0 or later installed, or if you have
+Scalar-List-Utils 1.03 or later installed, you can say:
+
+ use List::Util 'shuffle';
+
+ @shuffled = shuffle(@list);
+
+If not, you can use this:
# fisher_yates_shuffle( \@array ) :
# generate a random permutation of @array in place
@@ -1213,6 +1220,10 @@
fisher_yates_shuffle( \@array ); # permutes @array in place
+Note that the above implementation shuffles an array in place,
+unlike the List::Util::shuffle() which takes a list and returns
+a new shuffled list.
+
You've probably seen shuffling algorithms that work using splice,
randomly picking another element to swap the current element with
End of Patch.