?rand(2)=1 twice oddity
- Posted by Pete Lomax <petelomax at bluey?n?er.co.uk> Dec 13, 2007
- 469 views
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