Data::RandomPerson::Choice - Select an element from a list in proportion
This document refers to version 0.4 of Data::RandomPerson::Choice, released Sept 13th, 2005
use Data::RandomPerson::Choice; my $c = Data::RandomPerson::Choice->new(); $c->add( 'this' ); $c->add( 'that', 11 ); # The list now contains 12 elements, 1 'this' and 11 'that'. A random # element will be selected with the following probablilty: # # this = 1/12 = 0.083 # that = 11/12 = 0.917 print $c->pick();
A way of simply defining the probablity of a selection of values based on the ratio of the elements this add( 'this' ) adds one element to the list, the count argument of add defaults to 1. add( 'that', 11 ) adds another 11 elements to the list giving a total of 12. The chance of picking 'this' is 1 in 12 and the change for 'that' is 11 in 12.
You can add as many values as you like to the list.
Returns a Data::RandomPerson::Choice object.
Adds VALUE to the list COUNT times, if COUNT is omitted it will default to 1.
Adds a LIST of items to the data
Returns the size of the list so far
Returns an element from the list.
This error will occur if you have called pick() before add() has been called.
None so far
Peter Hickman (firstname.lastname@example.org)
Copyright (c) 2005, Peter Hickman. All rights reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.