Name : perl-Acme-CPANModules-PickingRandomItemsFromList
| |
Version : 0.005
| Vendor : obs://build_opensuse_org/devel:languages:perl
|
Release : 1.9
| Date : 2024-08-05 17:56:20
|
Group : Unspecified
| Source RPM : perl-Acme-CPANModules-PickingRandomItemsFromList-0.005-1.9.src.rpm
|
Size : 0.03 MB
| |
Packager : (none)
| |
Summary : List of modules to pick random items from a list
|
Description :
If you are picking random lines from a file, there\'s a separate CPANModules list for it: Acme::CPANModules::PickingRandomLinesFromFile.
*1. Picking a single item, with equal probability*
If you only want to pick a single item, with equal probability, you can simply get a random element from an array using the \'$ary[rand AATTary]\' idiom.
*2. Picking multiple items, with equal probability*
*2a. Picking multiple items, with equal probability, duplicates allowed*
If you want to allow duplicates, you can repeatedly pick random elements from an array using the \'$ary[rand AATTary]\' idiom.
*2b. Picking multiple items, with equal probability, duplicates not allowed*
If you do not want to allow duplicates, there are several alternatives:
List::Util (from version 1.54, 2020-02-02) provides \'sample()\'. If you use an older version, you can use \'shuffle()\' then get as many number of samples as you need from the first elements of the array using slice (\'AATTshuffled[0..$num_wanted-1]\') or \'head()\'.
List::MoreUtils also provides \'samples()\'.
Keywords: sample, sampling.
*3. Picking item(s), with weights*
If you want to assign different weights to different items (so one item might be picked more likely), you can use one of these modules:
Array::Sample::WeightedRandom offers sampling without replacement (not allowing duplicates) or with replacement (allowing duplicates).
Random::Skew.
Data::Random::Weighted currently can only pick a single item.
|
RPM found in directory: /packages/linux-pbone/ftp5.gwdg.de/pub/opensuse/repositories/devel:/languages:/perl:/CPAN-A/openSUSE_Tumbleweed/noarch |