View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Random Number Generation

Roulette

If you run this, it will generate 250 spins of the wheel and plot them on
the activesheet. I do 250 just to "insure" I get at least one of each
number. The plotting is just to demonstrate that it is doing the right
thing (although the row and column numbers will be helpful to account for
the other types of betting.). You should be able to adapt it to your
purposes

Sub abc()
Dim results As Long, sRes As String
Dim sCol As String
Columns("A:D").Clear
For i = 1 To 250
results = Int(Rnd() * 38 + 1) - 2
If results = -1 Then
sRes = "00"
Else
sRes = CStr(results)
End If


Select Case results
Case -1, 0
sCol = "Green"
Case 1, 3, 5, 7, 9, 12, 14, 16, 18, 19, _
21, 23, 25, 27, 30, 32, 34, 36
sCol = "Red"
Case 2, 4, 6, 8, 10, 11, 13, 15, 17, 20, _
22, 24, 26, 28, 29, 31, 33, 35
sCol = "Black"
End Select
If sRes = "00" Or sRes = "0" Then
rw = 0
col = 0
Else
rw = Int((results - 1) / 3) + 1
col = ((results - 1) Mod 3) + 1
End If
If rw < 0 And col < 0 Then
With Cells(rw + 1, col)
.Value = results
If sCol = "Red" Then
.Interior.ColorIndex = 3
.Font.ColorIndex = 2
.Font.Bold = True
ElseIf sCol = "Black" Then
.Interior.ColorIndex = 1
.Font.ColorIndex = 2
.Font.Bold = True
End If
End With
Else
If sRes = "00" Then
With Cells(1, 3)
.Value = "'00"
.Interior.ColorIndex = 10
.Font.ColorIndex = 2
.Font.Bold = True
End With
Else
With Cells(1, 1)
.Value = "'0"
.Interior.ColorIndex = 10
.Font.ColorIndex = 2
.Font.Bold = True
End With
End If
End If
With Columns("A:C")
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
End With
Next i

End Sub



This generates 250 spins and maps each to a worksheet.


--
Regards,
Tom Ogilvy

"MB06" wrote in message
...
I am trying to simulate the results of 120 consecutive roulette wheel

spins.
There are 36 numbers on a roulette table, plus a "0" and a "00". So,
inherently, a 1/38 chance that any given number will be the result of a

spin.
I set the Random Number Generator to "Bernoulli" and a p-value of ".5" to
get the odds of a black v. red result, but this is not accurate because of
the "0" and "00" on the wheel. If anyone knows how to ask excel to

randomly
generate 38 different potential results, please email me back. Also, I

would
need a formula to translate each number to its corresponding color. I

don't
know if an "IF" statement would work here, or what is best, but I am
interested to hear the thoughts of experts.