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.