Velocity Reviews > Dice probability problem

# Dice probability problem

Tomi Lindberg
Guest
Posts: n/a

 04-05-2006
Antoon Pardon wrote:

> def __rmul__(self, num):
> tp = num * [self]
>
> 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)? Difference between the two methods is
slightly unclear to me.

Thanks,
Tomi Lindberg

Antoon Pardon
Guest
Posts: n/a

 04-06-2006
On 2006-04-05, Tomi Lindberg <(E-Mail Removed)> wrote:
> Antoon Pardon wrote:
>
>> def __rmul__(self, num):
>> tp = num * [self]
>>
>> 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