Roulette %'s

Pfeif0

New Member
Joined
Jun 13, 2006
Messages
14
HI,
I am trying to calculate probabilities of a frequency of occurance; what I'm looking for is probably best described by roulette: Say you are playing based on the first 3rd that has a 12/38 chance every time you play. If you use a specific betting strategy 5,10,15,20,30,45,70 etc what is the overall % chances for each; obviously it is 12/38 for the first try, but the next try you win if you hit the first or second time b/c of the betting etc...
Where my problem lies is every time I try to replicate (F9) and count failures or successes I can't figure out how to keep continually adding successes every time a diffferent random number generates. I'm sure there's a simple way to do that but I am hoping ya'll can help me out.
Thanks,
Keith
 
Improved the error trap in the code above and added the reset for the restults, so you can re-run without deleting the last results now. It also now lists the final tally to the botom of the results. Then your results are added to a log of cycle results. So, you should use this version.



Sub myRoulette()
'Standard module, like: Module1.
Dim mySpin%, maxNum%, numSpins%, spins%, myNum%, myEnd%, myBetC%
Dim myWinings&, myLosses&, myWiner&, myLose&, myBet&
Dim myFlagW As Boolean, myFlagL As Boolean, myLog As Boolean
Dim mySht As Worksheet
Dim winNum$, myResult$
Dim myRng As Range

Worksheets(1).Select
ActiveSheet.Name = "Roulette"
'Get bet Numbers!
myEnd = ActiveSheet.Range("IV2").End(xlToLeft).Column

Set myRng = ActiveSheet.Range(Cells(2, 1), Cells(2, myEnd))

'Add Title.
ActiveSheet.Range("D1").Select
ActiveSheet.Range("A1").Value = "Roulette, Gaming!"
ActiveSheet.Range("A1").Font.Bold = True
ActiveSheet.Range("A1").Font.Size = 16

'Test for no bets, Error!
If (myRng.Count = 1 And ActiveSheet.Range("A2").Value = "") Then
ActiveSheet.Range("A2").Select

MsgBox "In Row ""2"" please add:" & vbLf & _
"The numbers you wish to bet on, " & _
"starting in Column ""A""" & vbLf & _
"Only add one value to a Column/Cell!" & vbLf & vbLf & _
"Note: You may use 0 & 00, entered as text only," & vbLf & _
"enter them with a single quote first!"
Exit Sub
End If

'Add Labels.
ActiveSheet.Range("A3").Value = "Spin"
ActiveSheet.Range("B3").Value = "This Bet"
ActiveSheet.Range("C3").Value = "Losses"
ActiveSheet.Range("D3").Value = "Wins"
ActiveSheet.Range("E3").Value = "This Win"
ActiveSheet.Range("F3").Value = "Winner"
ActiveSheet.Range("G3").Value = "Wheel"
ActiveSheet.Rows("3:3").Font.Bold = True
ActiveSheet.Columns("F:F").HorizontalAlignment = xlCenter

If ActiveSheet.Range("A5").Value <> "" Then _
ActiveSheet.Range(Cells(5, 1), Cells(ActiveSheet.Range("A65536").End(xlUp).Row, 7)).Delete

'Get wheel!
maxNum = InputBox("What is the highest number on the wheel?" & vbLf & vbLf & _
"Note: The last two numbers will be converted to 0 and 00." & vbLf & _
"So, for 1 to 36 with 0 and 00, enter 38!", "Numbers to use!", 38)

'Get bet!
myBet = InputBox("What amount to add to the amount bet each spin?", "Enter bet pattern!", 5)
myBetC = myBet

'Get Number of spins/bets to make!
numSpins = InputBox("How many spins will you be making?", "Get Spin Cycles!", 100)

For spins = 1 To numSpins
'Initialize random-number generator.
Randomize
'Get random number for spin.
mySpin = Int((maxNum * Rnd) + 1)

'Get win or loss!
For Each Cell In myRng
If mySpin = maxNum Then
winNum = "00"
myFlagW = True
End If

If mySpin = (maxNum - 1) Then
winNum = "0"
myFlagW = True
End If

If (mySpin = Cell.Value And myFlagW = False) Then
winNum = mySpin
myFlagW = True
End If

ActiveSheet.Columns("F:F").NumberFormat = "@"
ActiveSheet.Columns("F:F").HorizontalAlignment = xlCenter
Next Cell

'Print win-loss info to sheet!
If myFlagW = False Then
'Tally losses.
myLose = myLose + myBet
ActiveSheet.Range("C" & 4 + spins).Value = "Lose"
myFlagL = True
End If

If myFlagL = False Then
'Calculate amount won?
myWiner = (myBet * (((myRng.Count / maxNum) / 2) * 100)) - ((myRng.Count - 1) * myBet)

ActiveSheet.Range("D" & 4 + spins).Value = "Win"
ActiveSheet.Range("E" & 4 + spins).Value = _
Application.WorksheetFunction.Text(myWiner, "$#,###")
ActiveSheet.Range("F" & 4 + spins).Value = winNum
End If

ActiveSheet.Range("A" & 4 + spins).Value = spins
ActiveSheet.Range("B" & 4 + spins).Value = _
Application.WorksheetFunction.Text(myBet, "$#,###")
myBet = myBet + myBetC

If myFlagW = True Then myWinings = myWinings + myWiner
If myFlagL = True Then myLosses = myLosses + myBet
ActiveSheet.Range("G" & 4 + spins).Value = mySpin

myFlagW = False
myFlagL = False
Next spins

If myWinings - myLosses > 0 Then
myResult = "profit"
Else
myResult = "loss"
End If

'Results message!
MsgBox "You spent: " & _
Application.WorksheetFunction.Text(myLosses, "$#,###") & vbLf & _
"You won: " & Application.WorksheetFunction.Text(myWinings, "$#,###") & _
vbLf & "Your " & myResult & " is: " & _
Application.WorksheetFunction.Text(Abs(myWinings - myLosses), "$#,###")

'Print results to sheet!
ActiveSheet.Range("A" & 6 + spins).Value = _
"You spent: " & _
Application.WorksheetFunction.Text(myLosses, "$#,###") & _
". You won: " & Application.WorksheetFunction.Text(myWinings, "$#,###") & _
". Your " & myResult & " is: " & _
Application.WorksheetFunction.Text(Abs(myWinings - myLosses), "$#,###") & "."

ActiveSheet.Range("A" & 7 + spins).Select

'Check for "Log" Sheet or Make "Log" Sheet!
For Each ws In Worksheets
If ws.Name = "Log" Then myLog = True
Next ws

If myLog = False Then
Set mySht = ActiveWorkbook.Sheets.Add

mySht.Name = "Log"
Sheets("Log").Move After:=Sheets(2)
End If

'Post results to log.
Sheets("Log").Range("A65536").End(xlUp).Offset(1, 0).Value = Date & "' " & Time
Sheets("Log").Range("A65536").End(xlUp).Offset(0, 1).Value = " Spent:"
Sheets("Log").Range("A65536").End(xlUp).Offset(0, 2).Value = _
Application.WorksheetFunction.Text(myLosses, "$#,###")
Sheets("Log").Range("A65536").End(xlUp).Offset(0, 3).Value = " Won:"
Sheets("Log").Range("A65536").End(xlUp).Offset(0, 4).Value = _
Application.WorksheetFunction.Text(myWinings, "$#,###")
Sheets("Log").Range("A65536").End(xlUp).Offset(0, 5).Value = " " & myResult & ":"
Sheets("Log").Range("A65536").End(xlUp).Offset(0, 6).Value = _
Application.WorksheetFunction.Text(Abs(myWinings - myLosses), "$#,###")
Sheets("Log").Range("A65536").End(xlUp).EntireRow.HorizontalAlignment = xlRight
Sheets("Log").Columns("A:G").Columns.AutoFit
Sheets("Log").Select
Sheets("Log").Range("A65536").End(xlUp).Select
Sheets("Roulette").Select

End Sub
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top