Beginners Query - Simple counter problem
iclark at mail.ewu.edu
Thu Sep 6 20:50:49 CEST 2007
Carsten Haese wrote:
> On Thu, 2007-09-06 at 11:24 -0700, Ian Clark wrote:
>> Carsten Haese wrote:
>>> def d6(count):
>>> return sum(random.randint(1, 6) for die in range(count))
>> My stab at it:
>> >>> def roll(times=1, sides=6):
>> ... return random.randint(times, times*sides)
> That produces an entirely different probability distribution if times>1.
> Consider times=2, sides=6. Your example will produce every number
> between 2 and 12 uniformly with the same probability, 1 in 11. When
> rolling two six-sided dice, the results are not evenly distributed. E.g.
> the probability of getting a 2 is only 1 in 36, but the probability of
> getting a 7 is 1 in 6.
Doh. I stand corrected. Probability was never a fun subject for me. :)
More information about the Python-list