Dice probability problem

Antoon Pardon apardon at forel.vub.ac.be
Thu Apr 6 04:17:30 EDT 2006


On 2006-04-05, Tomi Lindberg <tomi.lindberg.NO_SPAM at pp.inet.fi.invalid> wrote:
> Antoon Pardon wrote:
>
>>   def __rmul__(self, num):
>>     tp = num * [self]
>>     return reduce(operator.add, tp)
>> 
>> sum3d6 = 3 * D(6)
>
> One basic question: is there any particular reason not to 
> use __mul__ instead (that would allow me to use both 3 * 
> D(6) and D(6) * 3, while __rmul__ raises an AttributeError 
> with the latter)?

Well 3 * D(6) is similar to the notation used in roleplaying,
while D(6) * 3 would make me think of the distribution
{3:1, 6:1, 9:1, 12:1, 15:1, 18:}

> Difference between the two methods is 
> slightly unclear to me.

I have to look it up myself regularly. But in this case
it was more a matter of some intuition that 3 * D(6)
was not the same as D(6) * 3. You may have a different
intuition.

-- 
Antoon Pardon



More information about the Python-list mailing list