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

Stephen Warren swarren at wwwdotorg.org
Thu Apr 10 09:46:24 MDT 2008


On Wed, April 9, 2008 11:15 pm, Sean Reifschneider wrote:
> D1=`od --read-bytes=1 -t u1 /dev/random | head -1 | sed 's/.* //'`
> D1=$[(D1%6)+1]

I think that'll introduce some slight bias in the results; the byte has
range 0..255, which isn't exactly divisible by 6, so the 256 is divided
into a set of complete "6 sized" regions, followed by a "4 sized" region,
so I'd expect marginally more 1..4 than 5..6. Still, this is 1/42 of the
number space, so perhaps it won't be too obvious...

The impact of this could be somewhat reduced by pulling 16-bit numbers
from /dev/random, to reduce the proportion of the range that's a "partial
die". Or, perhaps we could do the experiment with 8-sided dice, so mod 8.




More information about the NCLUG mailing list