PDA

View Full Version : Generate random numbers based on odds



LOSS1574
07-01-2008, 12:28 PM
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.

Oorang
07-08-2008, 09:47 AM
Hi Loss,
Here is some code that will do a roughly what you laid out.
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


Remember that variance may occur between target results and the output, as the output is still random.