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

Jim Hutchinson jim at ubuntu-rocks.org
Thu Apr 10 08:49:53 MDT 2008


On Wed, Apr 9, 2008 at 7:02 PM, Stephen Warren <swarren at wwwdotorg.org>
wrote:

> So, I wrote a quick script that basically does:
>
> * Roll a pair of dice N times, and calculate Chi^2 against the expected
> distribution.
>
> * Repeat the above, keeping a record of each run's Chi^2 value, then
> calculate some stats on the set of Chi^2 values.
>
> It turns out that across 1000 iterations of 100000 dice-pair rolls, I
> got the following stats for Chi^2:
>
> Min:       1.04
> Mean:      9.88
> Max:      30.06
> Std.Dev.:  4.49
>
> >From memory, assuming a normal distribution of values, 67% of expected
> results will be within 1 SD of the mean.
>
> As such, any result within (at least) the range 5.4...14.4 is simply
> expected.
>
> (I guess I should also graph the set of Chi^2 values to ensure they look
> like a normal distribution)
>
> So, from memory last night's Ruby Chi^2 was like 10.x and Python's 14.x?
> As such, this isn't enough to imply that there's any meaningful
> difference between the PRNGs used by those two languages, based on a
> sample size of around 1-3 runs.
>
> As an aside, the large variation in Chi^2 is also probably expected,
> since any (P)RNG is expected to sometimes produce some pretty far-out
> results; see the random.org explanation for why their graphs that
> indicate random number quality sometimes indicate it's quite bad!
>

Cool. I'll play around a bit and show this to Leina. I'm attaching the
scripts she used for her project. Scott also did a cool little python script
to animate the distribution "live". I don't have that with me but I can
forward it later if that's okay with Scott.

The one called dice_game.py was the one Leina did using the book. It was
just to help her understand a bit about programming. I only attach it for
fun.
-- 
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