-
Generate random numbers based on odds
Any available programs or code to generate random number based on odds. See Attached Odds Chart
I would like to generate multiple unique list based on odds with the unique numbers 1 - 55.
for example in the chart, Account #1 is 10 times more likely to generate a number from 1-10 rather then the last number 55 when the first number is generated.
Last edited by LOSS1574; 07-02-2008 at 08:28 AM.
-
Hi Loss,
Here is some code that will do a roughly what you laid out.
[VBA]Public Sub test()
Dim ws As Worksheet
Dim i As Long
Set ws = ActiveSheet
Excel.Application.EnableEvents = False
For i = 1 To 65536
ws.Cells(i, 1).Value = GetBall
Next
Excel.Application.EnableEvents = True
End Sub
Public Function GetBall() As Long
Dim lngRtnVal As Long
Select Case RandBetween(1, 10000)
Case Is <= 1818
lngRtnVal = RandBetween(1, 10)
Case Is <= 3455
lngRtnVal = RandBetween(11, 19)
Case Is <= 4909
lngRtnVal = RandBetween(20, 27)
Case Is <= 6182
lngRtnVal = RandBetween(28, 34)
Case Is <= 7273
lngRtnVal = RandBetween(35, 40)
Case Is <= 8182
lngRtnVal = RandBetween(41, 45)
Case Is <= 8909
lngRtnVal = RandBetween(46, 49)
Case Is <= 9454
lngRtnVal = RandBetween(50, 52)
Case Is <= 9818
lngRtnVal = RandBetween(53, 54)
Case Else
lngRtnVal = 55
End Select
GetBall = lngRtnVal
End Function
Private Function RandBetween(num1 As Long, num2 As Long)
Const lngOffset_c As Long = 1
Randomize
RandBetween = Int((num2 - num1 + lngOffset_c) * Rnd + num1)
End Function
[/VBA]
Remember that variance may occur between target results and the output, as the output is still random.
Cordially,
Aaron
Keep Our Board Clean! - Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
- Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules