When I created my coin toss graphics program
https://www.qb64.org/forum/index.php?topic=4117.msg134684#msg134684 as a check that it was working correctly, there must not have been many consecutive same heads or tails (the program did seem OK in this respect).
But I wondered if you let QB64 run continuously with a 50/50 random, what would the maximum same consecutive be. [Theoretically (?) if you do 50/50 for an infinite time you'd get a sequence sometime of infinite consecutive same].
So this simple program examines this.
Count& = 0
Cycle& = 0
SameCount% = 0
MaxSame% = 0
Heads%% = True
Heads%% = False
OldHeads%% = Heads%%
Heads%% = True
Heads%% = False
SameCount% = SameCount% + 1
IF SameCount%
> MaxSame%
THEN MaxSame%
= SameCount%
SameCount% = 0
'IF Heads%% THEN
' OldHeads%% = False
'ELSE
' OldHeads%% = True
'END IF
OldHeads%%
= NOT OldHeads%%
'IF RND < 0.5 THEN
' Heads%% = True
' OldHeads%% = True
'ELSE
' Heads%% = False
' OldHeads%% = False
'END IF
Count& = Count& + 1
IF Count&
/ 10000000 = Count& \
10000000 THEN Count& = 0
Cycle& = Cycle& + 1
The program runs freely and occasionally prints the maximum number of same consecutive "heads or tails". On my laptop this number is 24, seemingly never exceeded. The likelihood of getting 24 same consecutive heads or tails is low (~ 1 in 16 million, but the program is doing billions of cycles). Occasionally, one might expect the maximum of 24 to be exceeded.
I think that I must be doing something stupid with the code.