- or download this
# ($k,$v) = rhe_1(%hash);
...
my $key = (keys %{ $_[0] })[rand keys %{ $_[0] }];
return ($key, delete $_[0]{$key});
}
- or download this
# @keys = keys %hash; # done ONCE
# ($k,$v) = rhe_2(%hash,@keys);
...
} until exists $_[0]{$_[1][$key]};
return ($_[0]{$_[1][$key]}, delete $_[0]{$_[1][$key]});
}
- or download this
# %seen = (); # done ONCE
# @array = ([k,v], [k,v], ...);
...
do { $idx = rand @{ $_[0] } } while $_[1]{int $idx}++;
return @{ $_[0][$idx] };
}