I'm quite sure that I don't understand your reference to "randomly select a string with four elements from a data frame with 1553 strings..." -- so, as in Kenosis reply above, I've worked with a string comprised of "A" .. "Z" and taken a couple additional steps to obtain the one-thousandth permutation *1 (shuffle) thereof:
#!/usr/bin/perl
use 5.016;
use warnings;
use List::Util qw/shuffle/;
my $runs = 10^3;
my $range = 1553;
my @letterRange = ( 'A' .. 'Z' );
my $i = 0;
my (@array, @arr2, $key, $valref, $permutes);
my %permutes = ();
for ($i=1;$i<=$range;$i++) { # C-style, start w/"1"; "0" would g
+ive 1554 elements
@array = shuffle @letterRange for 1 ..$runs; # @arr will hold th
+e 1000th shuffle
$key = "@array";
$permutes {$key } = $i;
}
for my $key ( keys %permutes ) {
my $value = $permutes{$key};
push @arr2, "$value => $key";
}
print "size of hash: " . keys( %permutes ) . ".\n";
no warnings 'numeric';
my @sorted = sort {$a <=> $b} @arr2;
use warnings;
for $_ (@sorted) {
say $_;
}
The output looks like this:
size of hash: 1553.
1 => V Y N H D R W Q C B E F T L S I J M O U Z A G X P K
2 => W E C B M V P I Y U D K G A T Z R O N F S J L X Q H
3 => L A T Y N R C Z J O V U G Q H F B S K W I E X P M D
...
... no dupes, no missing iteration numbers found but a selection of the output is in the readmore which follows:
*1: Reiterating, I doubt this is the solution to your problem -- as noted above, I simply don't understand a part of your problem statement (and the code doesn't illuminate the meaning for /me) but I do hope this may offer an approach to your specific case.
|