#bbcmicrobot Simulate coinflips to calculate pi πŸš€
(long, so easy to understand!)

FOR L=13TO18: ?L=?-444: NEXT
C%=0
A=0
REPEAT
O=FNround(1)
C% = C% + 1
REM PRINT "Round", C%
REM PRINT "Game result", O
T=A * (C% - 1)
A=(T + O) / C%
PRINT "Pi after "; C%; " rounds is "; A * 4
UNTIL C% > 1000
END
DEF FNround(X)
REM flip coins until you've got more heads than tails, then return heads/flips
F%=0
H%=0
T%=0
REPEAT
R=RND(2)
IF R=1 THEN H% = H% + 1: ELSE T% = T% + 1
F% = F% + 1
UNTIL H% > T%
=H%/F%

I ran @sil's program and got this.
Source: https://bbcmic.ro/?t=dOwUe #bbcbasic
@bbcmicrobot hmph. Fine. I'll put rem statements in :)
REM #bbcmicrobot Simulate coinflips to calculate pi πŸš€
REM (easy to understand, I hope)
FOR L=13TO18: ?L=?-444: NEXT
C%=0
A=0
REPEAT
O=FNround(1)
C% = C% + 1
REM PRINT "Round", C%
REM PRINT "Game result", O
T=A * (C% - 1)
A=(T + O) / C%
PRINT "Pi after "; C%; " rounds is "; A * 4
UNTIL C% > 1000
END
DEF FNround(X)
REM flip coins until you've got more heads than tails, then return heads/flips
F%=0
H%=0
T%=0
REPEAT
R=RND(2)
IF R=1 THEN H% = H% + 1: ELSE T% = T% + 1
F% = F% + 1
UNTIL H% > T%
=H%/F%
I ran @sil's program and got this.
Source: https://bbcmic.ro/?t=dOwXQ #bbcbasic
@bbcmicrobot Nice. 3.2ish, that's not a bad estimate for pi. i can live with that :)
#bbcmicrobot πŸš€
REM @sil
DIM M 1024
FOR L=13TO17:?L=?-444: NEXT
FORL=M TOM+1023 STEP4:!L=RND:N.
C%=1:A=0
REPEAT
O=FNround(C%)
T=A*C%
C%=-NOTC%
A=(T+O)/C%
PRINT"Pi after "; C%; " rounds is "; A*4
UNTILC%>10000
END
DEFFNround(X%)
F%=0:H%=0:T%=0
REPEAT
R%=((M?((X%/8)MOD1023))/2^(X%MOD8))AND1
IFR%=1H%=-NOTH%ELSET%=-NOTT%
F%=-NOTF%:X%=-NOTX%
UNTILH%>T%
P.
=H%/F%
@geoffl considerably better estimate :-)

@sil

Same code with a couple of optimisations. it generates 1024 random bytes then uses that bitstream for 0s and 1s for coin flips, starting at the next bit for the starting point of each round (so there's a mistake and it should really end after 8192 rounds)

Also X% = -NOT X% is faster then X% = X% +1 and there are a lot of +1s to get through