in reply to random pairs
#!/usr/bin/perl use warnings; use strict; use List::Util 'shuffle'; my @random; LOOP: { @random = shuffle 0 .. 99; my %unique; for ( 0 .. $#random ) { redo LOOP if $_ == $random[ $_ ] || ++$unique{ $_ < $random[ $ +_ ] ? "$_,$random[$_]" : "$random[$_],$_" } > 1; } } my @pairs = map [ $_, $random[ $_ ] ], 0 .. $#random;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: random pairs
by CountZero (Bishop) on Jul 14, 2012 at 12:12 UTC |
In Section
Seekers of Perl Wisdom