in reply to Array problem
use List::Util qw(shuffle); use strict; use warnings; my @start = qw( dog cat bird mouse rat snake horse cow pig lizard lamb + zebra lion elephant monkey ); my @a = shuffle @start; for ( 0 .. $#a ) { print "@a[ $_, ($_+1)%@a, ($_+3)%@a, ($_+6)%@a ]\n"; }
The nice thing about this is that it does exactly one shuffle, and never calls rand (except insided the shuffle).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Array problem
by ikegami (Patriarch) on Sep 29, 2008 at 00:40 UTC |