The key is going to be getting the right percentage of each number. To begin with each number (1 to 10) has a 10% percent chance of begin picked. If you set the first five numbers to 50% then each would have to exist in the "pick list" twice as much as a number with a 25% chance and so on . . .
Here is what I came up with . . .
VB Code:
Option Explicit Dim i As Integer Dim x As Integer Dim z As Integer Dim intNumberEntries As Integer Dim intSum As Integer Private Sub Form_Load() List1.Clear List2.Clear For i = 1 To 10 List1.AddItem i List2.AddItem 10 Next i Text1.Text = "" Text2.Text = "" Debug.Print List1.ListCount & " " & List2.ListCount End Sub Private Sub List1_Click() List2.Selected(List1.ListIndex) = True Text1.Text = List2.List(List1.ListIndex) Text1.SetFocus Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) End Sub Private Sub List2_Click() List1.Selected(List2.ListIndex) = True End Sub Private Sub Text1_Change() If Text1.Text = "" Then Exit Sub List2.List(List1.ListIndex) = Text1.Text End Sub Private Sub Command1_Click() 'Here is where it gets interesting! List3.Clear intSum = 0 For i = 0 To List2.ListCount - 1 intSum = intSum + List2.List(i) Next i For i = 0 To List1.ListCount - 1 intNumberEntries = ((List2.List(i)) / 100) * intSum For x = 1 To intNumberEntries List3.AddItem List1.List(i) Next x Next i Randomize 'now lets get that number! z = (Rnd(1) * List3.ListCount) + 1 Text2.Text = List3.List(z) End Sub
and here is the form . . .




Reply With Quote