File Coverage

blib/lib/Acme/CPANModules/PickingRandomItemsFromList.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             package Acme::CPANModules::PickingRandomItemsFromList;
2              
3 1     1   396466 use strict;
  1         3  
  1         222  
4              
5             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
6             our $DATE = '2025-05-22'; # DATE
7             our $DIST = 'Acme-CPANModules-PickingRandomItemsFromList'; # DIST
8             our $VERSION = '0.006'; # VERSION
9              
10             our $LIST = {
11             summary => 'List of modules to pick random items from a list',
12             description => <<'MARKDOWN',
13              
14             If you are picking random lines from a file, there's a separate CPANModules list
15             for it: .
16              
17             **1. Picking a single item, with equal probability**
18              
19             If you only want to pick a single item, with equal probability, you can simply
20             get a random element from an array using the `$ary[rand @ary]` idiom.
21              
22              
23             **2. Picking multiple items, with equal probability**
24              
25             **2a. Picking multiple items, with equal probability, duplicates allowed**
26              
27             If you want to allow duplicates, you can repeatedly pick random elements from an
28             array using the `$ary[rand @ary]` idiom.
29              
30             **2b. Picking multiple items, with equal probability, duplicates not allowed**
31              
32             If you do not want to allow duplicates, there are several alternatives:
33              
34             (from version 1.54, 2020-02-02) provides `sample()`. If you use
35             an older version, you can use `shuffle()` then get as many number of samples as
36             you need from the first elements of the array using slice
37             (`@shuffled[0..$num_wanted-1]`) or `head()`.
38              
39             also provides `samples()`.
40              
41             Keywords: sample, sampling.
42              
43              
44             **3. Picking item(s), with weights**
45              
46             If you want to assign different weights to different items (so one item might be
47             picked more likely), you can use one of these modules:
48              
49             offers sampling without replacement (not
50             allowing duplicates) or with replacement (allowing duplicates).
51              
52             .
53              
54             currently can only pick a single item.
55              
56              
57             **Tangentially-related modules**
58              
59             provides CLI to pick random items from
60             command-line arguments.
61              
62             MARKDOWN
63             tags => ['task', 'sampling', 'random'],
64             entries => [
65             {
66             module=>'List::Util',
67             },
68             {
69             module=>'List::MoreUtils',
70             },
71             {
72             module=>'Array::Sample::WeightedRandom',
73             },
74             {
75             module=>'Random::Skew',
76             },
77             {
78             module=>'Data::Random::Weighted',
79             },
80             ],
81             };
82              
83             1;
84             # ABSTRACT: List of modules to pick random items from a list
85              
86             __END__