On 2010-12-05, Paul Rubin <no.em...@nospam.invalid> wrote: > Tim Harig <user...@ilthio.net> writes: >> A friend was trying to derive a mathematical formula for determining >> the possibly distribution of results from rolling arbitrariy numbers >> of m n-sided dice > > http://en.wikipedia.org/wiki/Multinomial_distribution
I sure he rediscovered much of that. Working that out for himeself was probably far more educational then simply reading an article on the solution. >> To generate a listing of all (non-uniq) possible roles, I would call >> the first dices increment method read and read the dice faces into a >> log until the first dice threw an exception that it could not be >> further incremented. Then I would call reset() on the first dice and >> increment the second and so on much like the odometer of a car. > > from itertools import product > m, n = 5, 2 > for roll in product(*(xrange(1,m+1) for i in xrange(n))): > print roll The fact that I bothered to create classes for the dice and roles, rather then simply iterating over a list of numbers, should tell you that I produced was of a far more flexible nature; including the support for roles with dice having different numbers of sides. I basically created a DSL that he could use to generate and automatically calculate the properties of series of roles defined by one or more varying property. I merely posted a simplied description of the dice-role objects because I thought that it demonstrated how exceptions can provide eligance of control for situations that don't involve what would traditionally be defined as an error. -- http://mail.python.org/mailman/listinfo/python-list