Guest User

Untitled

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