NAME

Array::Pick::Scan - Pick random items from an array (or iterator), without duplicates

VERSION

This document describes version 0.002 of Array::Pick::Scan (from Perl distribution Array-Pick-Scan), released on 2020-05-18.

SYNOPSIS

use Array::Pick::Scan qw(random_item);

my $item  = random_item(\@ary);
my @items = random_line(\@ary, 3);

or:

my $item  = random_item(\&iterator);
my @items = random_line(\&iterator, 3);

DESCRIPTION

This module can return random items from an array (or iterator), without duplicates. It uses the same algorithm as File::Random::Pick, which in turn uses a slightly modified version of algorithm described in perlfaq ("perldoc -q "random line"")), but uses items from an array/iterator instead of lines from a file(handle).

Performance-wise, this module is inferior to List::Util's shuffle or List::MoreUtils's samples, but can be useful in cases where you have an iterator and do not want to put all the iterator's items into memory first.

FUNCTIONS

random_item

Usage:

my @items = random_item(\@ary      [ , $num_samples ]);
my @items = random_item(\&iterator [ , $num_samples ]);

Number of samples defaults to 1.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Array-Pick-Scan.

SOURCE

Source repository is at https://github.com/perlancar/perl-Array-Pick-Scan.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Array-Pick-Scan

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

File::Random::Pick

List::Util's shuffle

List::MoreUtils's samples

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 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.