Re: ?rand(2)=1 twice oddity
Pete Lomax wrote:
>
> I was using
> }}}
<eucode>
> if rand(2)=1 then
> ..
> else
> ..
> end if
> if rand(2)=1 then
> ..
> else
> ..
> end if
> </eucode>
{{{
> and noticed the second instance did not behave as expected, so I wrote the
> following
> two-line test program:
> }}}
<eucode>
> ?rand(2)=1
> ?rand(2)=1
> </eucode>
{{{
> While the first seemed reasonably random, about 35 to 50 successive runs
> display
> a 1 on the second line then the next 35 to 50 or so runs show 0's.
> Seems OK in a loop, appears to be just the second call to rand(2) after the
> application has started. Same on 2.4 and 3.0.1, exw and exwc.
>
> Can anyone confirm this, offer an explanation, and/or suggest an alternative
> way to generate a 50:50 probability quickly, preferrably not using one of the
> convoluted libs in the archives? Does not have to be owt fancy just not
> *regularly*
> delivering a 1 in 1,125,899,906,842,624 improbability!!
>
> Thanks,
> Pete
Select any section of memory using rand().
Run a checksum on them (add up the last bits)
if the last bit of total=1 then return 1
elsif last bit of total=0 then return 0
Don Cole
|
Not Categorized, Please Help
|
|