[NCLUG] Python v.s. Ruby, and PRNGs

Stephen Warren swarren at wwwdotorg.org
Thu Apr 10 21:50:27 MDT 2008


Jim Hutchinson wrote:
> For 2 6-sided dice,
> 
> possible_sums = range(number_of_dice, (number_of_dice * sides_per_die) + 1)
> 
> will give the range of 2 - 13 but the real range is 2 - 12.

The second parameter to range is the first number not in the range.

If you know C, then this might help:

range(start, after_end, step)

is:

for (i = start; i < after_end; i = i + step)

> For the chi_squared bit, does
> 
> chi_sq += ((mf - ef) ** 2) / ef
> 
> sum the values for each sum (looped per for dice_sum in possible_sums:)?
> Does the += part mean to add the current sum to the running total?

Yes. "a += b" is short-hand for "a = a + b"

FYI, in the above equation:
m == measured
e == expected
f == frequency
p (elsewhere) == probability

> 3)

Yeah, I was too lazy to format the Chi^2 stats results nicely:-(



More information about the NCLUG mailing list