perl5i: ARRAY/HASH->pick to get a random element
completed by: Prashan Dharmasena
mentors: Paul Johnson, Florian Ragwitz, Michael G Schwern
See perl5i: ARRAY/HASH->pick to get a random element
Pick N random elements out of a list or hash (in which case its the yet to be defined Pair). Modeled on Perl 6's pick. http://svn.pugscode.org/pugs/docs/Perl6/Spec/S32-setting-library/Containers.pod
method pick ( Int $number = 1 )
pick guarantees not to return the same element twice in a single call.
What should it return? If you just want to pick one it seems silly to return a list or array ref. But I don't want to make an exception for where $number = 1. Maybe $item = @array->pick_one.
If $number is greater than the size of the list, it returns the entire list, shuffled. $number = 0 returns an empty list.