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

Jim Hutchinson jim at ubuntu-rocks.org
Thu Apr 10 21:03:13 MDT 2008


On Thu, Apr 10, 2008 at 12:02 PM, Stephen Warren <swarren at wwwdotorg.org>
wrote:

> On Thu, April 10, 2008 10:58 am, Jim Hutchinson wrote:
> > Would you be willing to share the code you used? I'd like to
> > explore it and try and learn more myself.
>
> Sure. You can download the current version from:
>
> http://www.wwwdotorg.org/downloads/random/
>
> It's not the most elegant code, global variables and all, but it works.
>

Okay, that's cool but I understand about 5% of it. Of that 5% I have a
couple questions.

1)
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. I seem to recall
something about a range starting at 0 so for 6 numbers 0 - 5 you are fine
but if you want 1 - 6 you have to add one. However, shouldn't it be like 0 -
10 + 2? I know I'm wrong, just wondering why.

2)
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?

3)
My output from one run is

{1000: (1.5085999999999986, 28.226599999999998, 9.9513805999999931,
4.3724560678574722, 0.43938185500185523), 10000: (1.2317000000000031,
38.773400000000002, 10.230084739999999, 4.717652005943842,
0.46115473388970601), 100: (1.4600000000000004, 27.800000000000001,
9.9632120000000022, 4.4447564463146909, 0.44611681918589002)}

I see that the first part after the 1000: is min, max, mean, std and I guess
std/mean but I can't figure out the rest. Any help?

If I understood more I'd probably have more questions (or maybe none).

I showed it to Leina and she said "kewl". She also noticed that some of the
chi squares were "too big". There is some interesting stuff here that
warrants further exploration. Thanks for doing this.




-- 
Jim (Ubuntu geek extraordinaire)
----
Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html



More information about the NCLUG mailing list