NAME

Array::Sample::WeightedRandom::Scan - (DO NOT USE) Sample elements randomly, with weights, without replacement (using scan algorithm)

VERSION

This document describes version 0.005 of Array::Sample::WeightedRandom::Scan (from Perl distribution Array-Sample-WeightedRandom), released on 2022-05-22.

SYNOPSIS

 use Array::Sample::WeightedRandom::Scan qw(sample_weighted_random_no_replacement);

 # "b" will be picked more often because it has a greater weight. it's also more
 # likely to be at the front of the samples.
 sample_weighted_random_with_replacement([ ["a",1], ["b",2.5] ], 1); => ("b")
 sample_weighted_random_with_replacement([ ["a",1], ["b",2.5] ], 1); => ("a")
 sample_weighted_random_with_replacement([ ["a",1], ["b",2.5] ], 1); => ("b")
 sample_weighted_random_no_replacement([ ["a",1], ["b",2.5] ], 5); => ("b", "a")

DESCRIPTION

DO NOT USE. This algorithm currently produces biased results where the items at the beginning will be picked at probabiity not quite according to their weights. Use Array::Sample::WeightedRandom instead.

This module provides "sample_weighted_random_no_replacement" which is the same as the one provided by Array::Sample::WeightedRandom but uses the scan algorithm. It actually scans the array twice instead of once.

FUNCTIONS

sample_weighted_random_no_replacement

See documentation of Array::Sample::WeightedRandom.

FAQ

Why no sample_weighted_random_with_replacement?

This kind of sampling does not require scanning algorithm.

HOMEPAGE

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

SOURCE

Source repository is at https://github.com/perlancar/perl-Array-Sample-WeightedRandom.

SEE ALSO

Array::Sample::WeightedRandom

Other sampling methods: Array::Sample::Partition, Array::Sample::SysRand, Array::Sample::SimpleRandom.

AUTHOR

perlancar <perlancar@cpan.org>

CONTRIBUTING

To contribute, you can send patches by email/via RT, or send pull requests on GitHub.

Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:

 % prove -l

If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla plugin and/or Pod::Weaver::Plugin. Any additional steps required beyond that are considered a bug and can be reported to me.

COPYRIGHT AND LICENSE

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

BUGS

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

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.