G
gamo
It's a better way to do this?
my @matrix = 1..10_000_000;
sub extract{
my $ind = int rand ($#matrix+1);
($matrix[$ind],$matrix[-1]) = ($matrix[-1],$matrix[$ind]);
return pop @matrix;
}
The goal is to extact random elements without using shuffle, and
ever removing them from the original list.
TIA
my @matrix = 1..10_000_000;
sub extract{
my $ind = int rand ($#matrix+1);
($matrix[$ind],$matrix[-1]) = ($matrix[-1],$matrix[$ind]);
return pop @matrix;
}
The goal is to extact random elements without using shuffle, and
ever removing them from the original list.
TIA