in reply to Re: picking multiple random elements out of an array
in thread picking multiple random elements out of an array
(The overly specific name indicates sloppy thinking on my part, for which I plead guilty.)# @indices = randomsubset(scalar @array, $size_of_subset); sub randomsubset { my @indices = 0 .. $_[0] - 1; my @subset = (); push @subset, splice(@d, int rand @indices, 1) for 1 .. @_[1]; @subset; } print join (" ", randomsubset(50,5)), "\n";
IIRC, there's something equivalent in the Cookbook.
|
|---|