There's more than one way to do things | |
PerlMonks |
Re^3: Pick k numbers at random -- hash keysby Discipulus (Canon) |
on Nov 12, 2019 at 20:48 UTC ( [id://11108594]=note: print w/replies, xml ) | Need Help?? |
Hello haukex, just for fun a solution exploiting the randomness of hash keys.
It is slightly faster than samp for very small sets..
..but becomes fastly slower ;) for bigger ones.
The only thing to note is the %{+{ LIST }} syntax, where + is used to disambiguate a hashref from a block (credit: perl IRC channel) because you can't dereference a map as a hash. PS: your hardware is ~3 times faster than mine ;) PPS: "randperm" is not exported by the Math::Prime::Util module in 0.60 so i upgraded to 0.73 L*
There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
In Section
Seekers of Perl Wisdom
|
|