in reply to (tye)Re: Efficient random hash stuff
in thread Efficient random hash stuff
Thank you muchly, tye. I need to ++ YOU, not your node...sub rand_element (\@); @array = ([1,2], [3,4], [5,6]); # etc... ($k,$v) = rand_element(@array); sub rand_element (\@) { my $aref = shift; my $idx = rand @$aref; my ($k,$v) = @{ $aref->[$idx] }; my $last = pop @$aref; $aref->[$idx] = $last if $idx < @$aref; return ($k,$v); }
|
---|
Replies are listed 'Best First'. | |
---|---|
(tye)Re2: Efficient random hash stuff
by tye (Sage) on Nov 17, 2000 at 01:34 UTC | |
by japhy (Canon) on Nov 17, 2000 at 01:40 UTC |