LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
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.





 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
random number generation Ahmad Excel Discussion (Misc queries) 3 November 6th 06 06:27 PM
random number generation DSpec Excel Worksheet Functions 7 October 3rd 05 01:41 PM
I need help with random number generation David Stoddard Excel Worksheet Functions 10 March 28th 05 07:06 AM
Random number generation Stratuser Excel Programming 7 March 15th 05 12:51 PM
random number generation nyn04[_5_] Excel Programming 3 September 22nd 04 02:13 PM


All times are GMT +1. The time now is 06:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"