NAME
ArrayDataRole::Util::Random - Provide utility methods related to getting random elment(s)
VERSION
This document describes version 0.001 of ArrayDataRole::Util::Random (from Perl distribution ArrayDataRoles-Standard), released on 2021-04-13.
DESCRIPTION
This role provides some utility methods related to getting random element(s) from the array. Note that the methods perform a full, one-time, scan of the array using get_elem
. For huge array, this might not be a good idea. Seekable array can use the more efficient ArrayDataRole::Util::Random::Seekable.
PROVIDED METHODS
get_rand_elem
Usage:
my $elem = $ary->get_rand_elem; # might return undef
Get a single random element from the array. If array is empty, will return undef.
get_rand_elems
Usage:
my $elems = $ary->get_rand_elems($n);
Get $n
random elements from the array. No duplicate elements (doesn't mean there won't be any duplicates, if the array originally contains duplicates). If array contains less than $n
elements, only that many elements will be returned.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/ArrayDataRoles-Standard.
SOURCE
Source repository is at https://github.com/perlancar/perl-ArrayDataRoles-Standard.
BUGS
Please report any bugs or feature requests on the bugtracker website https://github.com/perlancar/perl-ArrayDataRoles-Standard/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
SEE ALSO
ArrayDataRole::Util::Random::Seekable
Other ArrayDataRole::Util::*
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2021 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.