shuffle#

Return the input list in a uniformly random order.

תקציר#

my @mixed = shuffle @values;
my @deck  = shuffle 0..51;       # a shuffled deck

מה מוחזר#

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.

דוגמאות#

my @picked = shuffle @candidates;
my ($winner) = shuffle @entries;       # pick one at random
local $List::Util::RAND = sub { 0.5 }; # deterministic for tests

הבדלים מן ה-upstream#

Fully compatible with upstream.

ראו גם#

  • sample - take a fixed count without replacement.

  • head - deterministic prefix selection.