summaryrefslogtreecommitdiff
path: root/pod/perlfaq4.pod
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2001-09-04 12:04:16 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2001-09-04 12:04:16 +0000
commit45bbf655cf4c44e2bcace54d7637687816f35100 (patch)
tree0d83fa4e7a0ae8f5fd9ffdf72f24e228adbf4ff0 /pod/perlfaq4.pod
parent403ede60f1a0aaad407a59c0b9d3b6a54e6079b7 (diff)
downloadperl-45bbf655cf4c44e2bcace54d7637687816f35100.tar.gz
Update the FAQ now that Scalar-List-Utils 1.03 has shuffle().
p4raw-id: //depot/perl@11855
Diffstat (limited to 'pod/perlfaq4.pod')
-rw-r--r--pod/perlfaq4.pod13
1 files changed, 12 insertions, 1 deletions
diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod
index 826d793a71..7dcb881a46 100644
--- a/pod/perlfaq4.pod
+++ b/pod/perlfaq4.pod
@@ -1198,7 +1198,14 @@ lists, or you could just do something like this with an array:
=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 @@ Use this:
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