After making those changes, you're left with basically the same solution I proposed in my first reply in this thread.
I liked your idea of combining the arrays initially because, if you do it right, it allows the choosing of a random element to be an O(1) operation instead of an iterative one which is dependent on the distribution of valid and invalid elements. You can achieve this and still permit duplicate members with some additional setup.
my @one = qw( 1 3 5 7 9 11 13 13 15 15 17 19 21 23 ); my @two = qw( 1 5 9 13 17 21 ); my %valid; $valid{$_}++ for @one; @valid{@two} = (0) x @two; @choices = map { ($_) x $valid{$_} } keys %valid; sub randelt { $choices[rand @choices] }
-sauoq "My two cents aren't worth a dime.";
In reply to Re: Re^3: Choosing a random product from an Array
by sauoq
in thread Choosing a random product from an Array
by krisraman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |