in reply to getting random number 8 times never the same
The following would do the trick:
my @selection = @nums; for (0..7) { my $i = $_ + rand(@selection - $_); ($selection[$_], $selection[$i]) = ($selection[$i], $selection[$_]) } splice(@selection, 8);
But it would be better (simpler, cleaner, faster) to just use List::Util's shuffle.
use List::Util qw( shuffle ); my @selection = (shuffle(@nums))[0..7];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: getting random number 8 times never the same
by Anonymous Monk on Oct 31, 2010 at 17:14 UTC |