BCC said:
Just that there should be no duplicate coordinates generated... and to
retroactivly correct my post, here was the first attempt, extracted and
modified from a web site:
use strict;
use warnings;
my @shuffle = &getCoords;
Don't call subs with & for no good reason.
sub getCoords {
my @nums = (1..100);
this variable serves no good purpose. Only it's size is used in a
meaningful way, so just use that size directly (or a scalar holding the
size).
my %random = ();
my $num = 0;
This variable serves no good purpose. It only stores the size of the hash,
which is easy enough to just use directly. (Of course, if you need a
multi level hash for the "real" solution, then $num may come in handy yet.)
until (1000 == keys %random) {
my $i = int($nums[rand(@nums)]);
my $i = int(rand 100)+1;
I'd prefer to set it to () rather than 1, but no big deal.
no longer necessary.
}
return(keys %random);
}
Ok, so now that you showed it to us, why doesn't it do what you want
it to do? Is it because you want it be nonrepeating among
all three dimensions simultaneously, but possible to repeat within any
single dimenstion considered alone? If that is the case, I'd just change
the one line to:
my $i=join"\t",int(rand 100)+1,int(rand 100)+1,int(rand 100)+1;
And then use map and split to munge the keys into the desired format at
the end:
return map [split /\t/], keys %random;
You could use multi-level hash instead, but I wouldn't bother in this
case.
Xho