Algorithm::Voting::Sortition - implements RFC 3797, "Publicly Verifiable Nominations Committee (NomCom) Random Selection"
To choose two of our favorite Hogwarts pals via sortition:
use Algorithm::Voting::Sortition; # choose a list of candidates my @candidates = qw/ Harry Hermione Ron Neville Albus Severus Ginny Hagrid Fred George /; # the results of our predetermined entropy source my @keysource = ( [32,40,43,49,53,21], # 8/9/08 powerball numbers "W 4-1", # final score of 8/8/08 Twins game ); # use sortition to determine the winners my $race = Algorithm::Voting::Sortition->new( candidates => \@candidates, source => \@keysource, n => 2, ); printf "Key string is: '%s'\n", $race->keystring; print $race->as_string;
Sortition is an unbiased method for "drawing straws" or "casting lots". This package implements the Sortition algorithm as described in RFC 3797, "Publicly Verifiable Nominations Committee (NomCom) Random Selection" (http://tools.ietf.org/html/rfc3797):
This document describes a method for making random selections in such a way that the unbiased nature of the choice is publicly verifiable. As an example, the selection of the voting members of the IETF Nominations Committee (NomCom) from the pool of eligible volunteers is used. Similar techniques would be applicable to other cases.
Constructs a new sortition object.
Example:
my $s = Algorithm::Voting::Sortition->new( candidates => [ 'A' .. 'Z' ], n => 3, source => [ $scalar, \@array, \%hash ], );
Returns a list containing the current candidates.
Returns the number of candidates that are to be chosen from the master list. If n is unspecified when the sortition object is constructed, the total number of candidates is used, i.e. the sortition will return a list containing all candidates.
n
Mutates the entropy source to be used in the sortition.
$obj->source(@entropy); # sets the entropy value my @e = $obj->source; # retrieves the entropy
Uses the current value of $self->source to create and cache a master "key string".
$self->source
Creates a "key string" from the input values in @source.
@source
Converts $thing into a string. $thing can be a scalar, an arrayref, or a hashref. If $thing is anything else, this method die()s.
$thing
die()
Returns a list containing the values of @items, but sorted. Sorts numerically if @items contains only numbers (according to Scalar::Util::looks_like_number()), otherwise sorts lexically.
@items
Scalar::Util::looks_like_number()
Calculates and returns the nth digest of the current keystring. This is done by bracketing $obj->keystring with a "stringified" version of $n, then calculating the MD5 digest of the result.
$obj->keystring
$n
The value returned is a 32-character string containing the checksum in hexadecimal format.
Returns a list of integers based on the dynamic keystring digest. These integers will be used will be used to choose the winners from the candidate pool.
Returns a data structure containing the contest results. For sortition, the structure is a list of candidates, with the first winner at list position 0, etc.
Returns the election results, formatted as a multiline string.
To install Algorithm::Voting, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Algorithm::Voting
CPAN shell
perl -MCPAN -e shell install Algorithm::Voting
For more information on module installation, please visit the detailed CPAN module installation guide.