1. ?rand(2)=1 twice oddity

I was using
if rand(2)=1 then
     ..
  else
     ..
  end if
  if rand(2)=1 then
     ..
  else
     ..
  end if

and noticed the second instance did not behave as expected, so I wrote the
following two-line test program:
?rand(2)=1
?rand(2)=1

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

new topic     » topic index » view message » categorize

2. Re: ?rand(2)=1 twice oddity

if rand(100) <= 50 then ...

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view message » categorize

3. 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

new topic     » goto parent     » topic index » view message » categorize

4. Re: ?rand(2)=1 twice oddity

Derek Parnell wrote:
> 
> if rand(100) <= 50 then ...

Thanks Derek. That probably expresses my intent better as well.

I just wasted >6 minutes of my life testing a theory:
Between 45:18 and 46:50 every run gave 0, between 46:50 and 48:17 they were all
1's, 48:17..49:49 0's, 49:49..51:20 1's

So it seems this behaviour is dependent on whether it is an odd or even multiple
of 90 seconds since some point in the past, at least on my box.

I guess it is just one of those things, best that could be done is shift this
anomaly somewhere else. Not to worry.

Regards,
Pete

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu