in reply to Simulating Drawing From A Bag
Shuffling via rand and splice isn't very efficient though on large arrays. Have a look at perldoc -q shuffle for an example of a fisher-yates shuffle#!/usr/bin/perl -w use strict; my @my_bag; @my_bag = (1..10); while (@my_bag > 0) { my $x = int(rand($#my_bag)); print splice(@my_bag, $x, 1) . "\n"; }
|
|---|