shuffle#
Return the input list in a uniformly random order.
Synopsis#
my @mixed = shuffle @values;
my @deck = shuffle 0..51; # a shuffled deck
What you get back#
A new list with the same elements as the input, permuted by a
Fisher-Yates shuffle. Each permutation is equally likely given a
well-distributed random source. The source is the global
$List::Util::RAND, or perl’s built-in rand() when $RAND is
undefined.
Examples#
my @picked = shuffle @candidates;
my ($winner) = shuffle @entries; # pick one at random
local $List::Util::RAND = sub { 0.5 }; # deterministic for tests
Differences from upstream#
Fully compatible with upstream.
See also#
sample— take a fixed count without replacement.head— deterministic prefix selection.