wrote:
> Using rand() in and old version og gcc, and using Tausworth's method, I
> calculated the frequency of 0 or 1 in the first digit like this:
>
> int hist[2] = {0,0};
>
> for (i = 0; i < 100000; ++i)
> {
> ++hist[prng() % 2];
> }
>
> For some reason, in both cases, 0 occurs more often than 1, no matter
> what seed I use to initialize the prng with. Something like 50150 vs
> 49850 in the above code.
>
> Does anybody know of a good "binary" PRNG, that is, one that in the
> above case would make something closer to 50000 vs 50000?
Note that the 50150 you mention is less than one-sixth
of one percent greater than a perfect fifty-fifty split. How
much "closer" do you think you need to be? How much "closer"
do you think a random sequence *ought* to be?
Let's see: If the outcomes (1 or 0) are equiprobable and
you make 100000 independent trials, the probability of getting
exactly 50000 of each outcome is the binomial probability
100000!
--------------- * 2^(-100000)
50000! * 50000!
If I'm not mistaken (I might be; these numbers are BIG), this
comes to 0.0025231262141967+; you can only expect a "perfect"
split about once in four hundred trials of a hundred thousand
numbers each. How many times have you run your experiment?
Let's see, take two: The expected number of 1's is 50000.
The variance is 100000*0.5*0.5 = 25000, so the standard
deviation is a little more than 158. You report a discrepancy
of 150, which is less than one standard deviation away from
a "perfect" split. I ask again: How much closer do you think
a random sequence can be while still being "random?"
Flip a coin twice. If get something other than heads once
and tails once, do you conclude that the coin is biased?
--
Eric Sosman
lid