A roullette wheel has 18 red, 18 black, and one zero slots. With each play of the game, a gambler bets $1 on red. Gambler’s initial capital is $10. A game is over when the gambler either wins $ 10 (his capital becomes $20) or becomes broke (capital = $0). Create a command button (B8) and assign it to a code to estimate the probability of becoming broke (D8). (use 10,000 simulation runs; you can use the VBA Rnd function as a random number generator) Run

48 0

Get full Expert solution in seconds

$1.97 ONLY

Unlock Answer

EXPERT ANSWER

the code is self explanatory

18 red balls

18 black balls 1 zero slot

probability of red ball is 18/37

probability of black ball is 18/37

probability of zero slot is 1/37

generate a random number in 0 to 1

if the number lies between 0 and 18/37 , its a red ball, increment money by 1

if the number lies between 18/37 and (18/37+18/37) its a black ball, decrement money by 1

if the number lies between (18/37+18/37) and 1 , then its a zero slot , decrement money by 1

if the money adds upto 20 its a play over

if the money becomes , its play over and brokecount is incremented by 1

iterate the above loop for 10,000 times , count brokecount

brokecount/10000 gives probability

Private Sub Play_Click()
Dim brokecount As Integer
Dim money As Integer
Dim probability As Long
Dim wincount As Integer
Dim flag As Integer
flag = 0
money = 10
brokecount = 0
For i = 1 To 10000
    While flag <> 1
        Randomize
        R = Rnd()
        If R <= 0.486 Then
            money = money + 1
        ElseIf R > 0.486 And R <= 0.972 Then
            money = money - 1
        ElseIf R > 0.972 Then
            money = money - 1
        End If
        If money = 20 Then
            flag = 1
        End If
        
        If money = 0 Then
            brokecount = brokecount + 1
            flag = 1

End If
        
    Wend
    flag = 0
    money = 10
Next i

Range("D8") = brokecount / 10000










End Sub