Skip Menu |
 

This queue is for tickets about the Scalar-List-Utils CPAN distribution.

Report information
The Basics
Id: 131535
Status: resolved
Priority: 0/
Queue: Scalar-List-Utils

People
Owner: Nobody in particular
Requestors: DBOOK [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.54



Subject: "sample" or "choice" function
Download (untitled) / with headers
text/plain 531b
It would be nice to have a function that returns a random element from the list. It could also be extended to allow specifying a number of random elements to return in one call, and whether to allow repeats - or just always disallow repeats, so the behavior of allowing repeats is implemented by calling the function multiple times. my @random_three = sample 3, @items; The only similar precedent I can find at the moment is the python "choice" and "choices" functions. https://docs.python.org/3/library/random.html#random.choice
Download (untitled) / with headers
text/plain 710b
On Tue Jan 21 16:13:10 2020, DBOOK wrote: Show quoted text
> It would be nice to have a function that returns a random element from > the list. It could also be extended to allow specifying a number of > random elements to return in one call, and whether to allow repeats - > or just always disallow repeats, so the behavior of allowing repeats > is implemented by calling the function multiple times. > > my @random_three = sample 3, @items; > > The only similar precedent I can find at the moment is the python > "choice" and "choices" functions. > https://docs.python.org/3/library/random.html#random.choice
It appears there is an existing attempt at this concept: https://github.com/Dual-Life/Scalar-List-Utils/pull/43
Example implementation via List::Util::PP: https://github.com/haarg/List-Util-MaybeXS/tree/sample
Download (untitled) / with headers
text/plain 194b
An initial attempt: https://github.com/Dual-Life/Scalar-List-Utils/tree/leonerd/sample I'd still like to get a consideration of $RAND (RT 131536) in before I commit it though. -- Paul Evans
Download (untitled) / with headers
text/plain 287b
On Mon Jan 27 20:17:45 2020, PEVANS wrote: Show quoted text
> An initial attempt: > > https://github.com/Dual-Life/Scalar-List-Utils/tree/leonerd/sample > > I'd still like to get a consideration of $RAND (RT 131536) in before I > commit it though.
Now handles $RAND. Awaiting CI tests -- Paul Evans
Merged -- Paul Evans
This is now on CPAN as part of 1.54 -- Paul Evans


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.