NAME
Games::Dice::Advanced  simulate dice rolls, including weird and loaded dice
SYNOPSIS
print Games::Dice::Advanced>roll(); # roll a sixsided die print Games::Dice::Advanced>roll('d4'); # roll a foursided die
# roll a foursided die and a 6sided die and return the total $die1 = Games::Dice::Advanced>new('d4'); $die2 = Games::Dice::Advanced>new('d6'); print Games::Dice::Advanced>roll($die1, $die2);
print $die1>roll(); # roll the d4 we created above
# roll 2 foursided dice and a 6sided die and return the total print Games::Dice::Advanced>roll('2d4', 'd6');
# create a foursided die with the squares of 1, 2, 3 and 4 Games::Dice::Advanced>new(sub { int(1+rand(4)) ** 2 });
METHODS
 roll

Roll one or more dice. If called as a class method, it first calls
appropriate constructors and creates objects before calling those objects'
roll()
methods. When called on an object it simply rolls the die. 
When called as a class method, it takes a list of arguments defining a 'recipe' to roll. These are added together to produce a result. Each item in the recipe must be a valid argument to the constructor (see the description of the 'new' method below). If no argument is given to a class method, we assume a sixsided die  'd6'. You will note that the multiplier constructor is not available when roll is called in this way.

When called as an object method, no arguments are permitted.
 new

This method defines a die. You may call it yourself to create a die for
later rolling, or it may be called by the
roll()
method. It takes zero, one or two arguments. If no argument is given, we silently assume that the user wants to create a sixsided die, a 'd6'. Valid arguments are:  integer constant, eg '5'
 Creates a die that always returns that constant
 dN, where N is integer, eg 'd10'
 Creates a die that returns a random integer from 1 to N with results spread evenly across the range.
 NdM, where N and M are integer, eg '2d10'
 Creates a die dM as above which is rolled N times to generate a result. Note that the N is *not* just a multiplier.
 N and any other valid argument, where N is a number, eg (2, 'd4')
 Note that the two arguments may be in any order. Creates a die as specified, and multiplies the results by N when it is rolled. Compare with NdM above.
Leading and trailing whitespace is stripped, no other whitespace is allowed in any of the above.
BUGS
For random, read 'pseudorandom'. Patches to work with sources of true randomness are welcome.
Doesn't support dice with fractional or complex numbers of sides :)
FEEDBACK
I welcome feedback about my code, including constructive criticism. And, while this is free software (both freeasinbeer and freeasinspeech) I also welcome payment. In particular, your bug reports will get moved to the front of the queue if you buy me something from my wishlist, which can be found at http://www.cantrell.org.uk/david/shoppinglist/wishlist.
AUTHOR
David Cantrell <david@cantrell.org.uk>
COPYRIGHT
Copyright 2003 David Cantrell
This module is freeasinspeech software, and may be used, distributed, and modified under the same terms as Perl itself.