none
Tossing Three Fair Coins RRS feed

  • Question

  • I have three fair coins and with the code below I am getting the # of try to get all three Heads. and I need to revise this code to get an average # of 10000 try for getting three heads. It should be something so near to 8 (1/2*1/2*1/2) 

    Can you help me 

    Sub ThreeHeadsTogether()
    '
    ' ThreeHeads Macro
    ' Three Heads
    '

    ThreeHeads = False
        Do While ThreeHeads = False
        CoinTossNumber = CoinTossNumber + 1

            Coin1 = Application.WorksheetFunction.RandBetween(1, 2)
            Coin2 = Application.WorksheetFunction.RandBetween(1, 2)
            Coin3 = Application.WorksheetFunction.RandBetween(1, 2)
                If Coin1 = 1 And Coin2 = 1 And Coin3 = 1 Then
                ThreeHeads = True
        End If
        Loop
        MsgBox CoinTossNumber

    End Sub

    Monday, April 29, 2019 2:42 AM

All replies

  • Hi,

    This forum is discussing and asking questions about the vb.net,your issue is  related about vba?I think you can set a loop to add up to 10,000 results and divide by 10,000.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 29, 2019 5:46 AM