NAME
TableDataRole::Util::Random - Provide utility methods related to getting random rows
VERSION
This document describes version 0.007 of TableDataRole::Util::Random (from Perl distribution TableDataRoles-Standard), released on 2021-04-11.
DESCRIPTION
This role provides some utility methods related to getting random rows from the table. Note that the methods perform a full, one-time, scan of the table using get_row_arrayref
or get_row_hashref
. For huge table, this might not be a good idea. Seekable table can use the more efficient TableDataRole::Util::Random::Seekable.
PROVIDED METHODS
get_rand_row_arrayref
Usage:
my $aryref = $table->get_rand_row_arrayref;
Get a single random row from the table. If table is empty, will return undef.
get_rand_rows_arrayref
Usage:
my $aoa = $table->get_rand_rows_arrayref($n);
Get $n
random rows from the table. No duplicate rows. If table contains less than $n
rows, only that many rows will be returned.
get_rand_row_hashref
Usage:
my $hashref = $table->get_rand_row_hashref;
Get a single random row from the table. If table is empty, will return undef.
get_rand_rows_hashref
Usage:
my $aoh = $table->get_rand_rows_hashre($n);
Get $n
random rows from the table. No duplicate rows. If table contains less than $n
rows, only that many rows will be returned.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/TableDataRoles-Standard.
SOURCE
Source repository is at https://github.com/perlancar/perl-TablesRoles-Standard.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=TableDataRoles-Standard
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
TableDataRole::Util::Random::Seekable
Other TableDataRole::Util::*
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2021, 2020 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.