
dim n as integer
dim tosses as integer

dim m as integer


dim x as double

dim win as integer

dim count as integer

dim winnings(500000) as integer


dim highest as integer





for n = 1 to 500000

    winnings(n) = 0
    
next



tosses = 256

for n = 1 to 30000000  'thirty million trials
    
    'print n
        win = 0
        
        for m = 1 to tosses
            
            count = 0
            
            do 
                count = count + 1
                x = rnd
            loop while x > 0.5
    
                win = win + 2^(count-1)
    
        next    
    
    
    if win <= 500000 then winnings(win) = winnings(win) + 1
    
    
next
    
    
highest = 500001

do
    
    highest = highest - 1
    
loop while winnings(highest) = 0



for n = tosses to tosses+20 'highest
    
    print n, winnings(n)
    
next


open "stpeter"+str(tosses)+".csv" for output as #1

print #1, "Winnings, Occurances"

for n = 1 to 1000
    
print #1, n ;","; winnings(n)


next

close #1

sleep


end

    
    
    
    
    