Guest User

Untitled

a guest
Mar 6th, 2012
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub Dalembert()
  2.     Dim trial As Long
  3.     Dim trials As Long
  4.     Dim winLoss As Long
  5.     Dim bet As Integer
  6.     Dim handle As Long
  7.     Dim wins As Long
  8.     Dim losses As Long
  9.    
  10.     trials = 1000000000 '1 Billion
  11.    
  12.     Randomize 'Init RNG
  13.    
  14.     bet = 1 'Start at a 1 unit
  15.    For trial = 1 To trials
  16.         handle = handle + bet 'Get the handle to be used for the average bet
  17.        If Int(2 * Rnd) = 1 Then 'WINNER!
  18.            wins = wins + 1 'Win counter
  19.            winLoss = winLoss + bet 'Add the bet to the current win
  20.            'A round was won so drop the bet by 1 unit to a minimum of 1 unit
  21.            If bet > 1 Then
  22.                 bet = bet - 1
  23.             End If
  24.         Else 'Loser
  25.            losses = losses + 1 'Loss counter
  26.            winLoss = winLoss - bet 'Subtract the bet from the current win
  27.            'A round was lost so add one to the bet
  28.            bet = bet + 1
  29.         End If
  30.     Next trial
  31.    
  32.     Debug.Print "Trials: " & trials
  33.     Debug.Print "Wins: " & wins & " (" & wins / trials * 100 & "%)"
  34.     Debug.Print "Losses: " & losses & " (" & losses / trials * 100 & "%)"
  35.     Debug.Print "Total Bet: " & handle
  36.     Debug.Print "Average Bet: " & handle / trials
  37.     Debug.Print "Win/Loss: " & winLoss
  38.     Debug.Print "Edge: " & winLoss / handle
  39. End Sub
Advertisement
Add Comment
Please, Sign In to add comment