have fun

Code: Select all

`declare function gcd(a as uinteger, b as uinteger) as uinteger`

dim as ulongInt prime1, count

dim as ulongInt ii=1

dim as uinteger ints = &hFFFF

screen 19

do

if gcd(int(rnd*ints+1), int(rnd*ints+1)) = 1 then prime1 +=1

count += 1

if count mod 10000 = 0 then print ii,"- Pi: "; sqr(6/(prime1 / count)), count, prime1: ii += 1

loop until inkey$ = "q" or count = 9223372036854775807

sleep

function gcd(a as uinteger, b as uinteger) as uinteger

dim as double an, bn

dim as ushort nn

if a < b then nn = a else nn = b

for n as ushort = nn to 1 step -1

an = a/n

bn = b/n

if an = int(an) andalso bn = int(bn) then return n

next

return 0

end function