http://qs321.pair.com?node_id=143173


in reply to picking multiple random elements out of an array

Here's an extension of the FAQ's method for selecting a random line from a file. This one selects multiple lines/entries. It keeps the selected entries in their original order.
my $count = 5; my @select; my $i = 0; for (@array) { push @select, $_ if rand() < ($count / ++$i); if (@select > $count) { splice(@select, rand($#select), 1); } }