Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I know that to get a random number it's just Math.Random(int)
But that gives me one random number, what I would like is a function that could get me an array of random numbers, for example:
Random of 6 #s: 1,3,4,5,0,2

I'm not exactly sure how to use the Math.Random method you are referring to, but here's how you could randomize an an array of numbers:
Not the most efficient way, though...
First, make a list box on the form called List1 and put this code into a Command button:
Dim RndNums(5) As Integer
Dim Rnd1 As Integer
Dim Counter1 As IntegerPrivate Sub Command1_Click()
List1.Clear
For i = 0 To 5
List1.AddItem i
Next iCounter1 = 0
Do Until Counter1 = 6
Rnd1 = Int(Rnd * List1.ListCount)
RndNums(Counter1) = List1.List(Rnd1)
List1.RemoveItem Rnd1
Counter1 = Counter1 + 1
LoopFor i = 0 To 5
List1.AddItem RndNums(i)
Next i
End Sub
-Burbble

this short line of code does thesame thing as the code mentioned above (i've used thesame form with the cmdbutton and the list)
Private Sub Command1_Click()
List1.Clear
Dim a As Integer
For i = 1 To 6
a = Int(Rnd * 10) + 1
List1.AddItem a
Next iEnd Sub

Forgot to mention that this one genarates numbers between 10 and 1. To generate numbers between 2 other numbers, replace 10 with the highest number and 1 with the lowest number.

![]() |
Need commands in VBE 6.0 ...
|
Combo Boxes
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |