1. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
May 2003
Posts
3
Rep Power
0

#### Identifying Singular Parts of Arrays

Okay here's my problem. I want to generate 4 random numbers, yet I don't want any of them to be the same. I need to know if theres a way (while using arrays) to say
Loop While number(#'s) = number(1 to 3)
so that i dont have to type
Loop while number(#'s) = number(1) or number(2) or number(3)
because i'm going to be working with a very large array and i still need all the numbers which are randomly generated to be unique.

Dim number(1 To 4) As Integer

Private Sub Command1_Click()
number(1) = Int((4 - 1 + 1) * Rnd + 1)
Do
number(2) = Int((4 - 1 + 1) * Rnd + 1)
Loop While number(2) = number(1)
Do
number(3) = Int((4 - 1 + 1) * Rnd + 1)

''''''''''''''''''I get an error here on next line (error = crash)

Loop While number(3) = number(1 Or 2)
Do
number(4) = Int((4 - 1 + 1) * Rnd + 1)

''''''''''''''''''I get an error here too on next line (error = crash)

Loop While number(4) = number(1 Or 2 Or 3)

Label1.Caption = number(1)
Label2.Caption = number(2)
Label3.Caption = number(3)
Label4.Caption = number(4)
End Sub
Last edited by JeffTerry; May 19th, 2003 at 01:18 PM.
2. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
May 2003
Posts
3
Rep Power
0

Help would be much appreciated...
3. No Profile Picture
epl
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2001
Location
Dublin
Posts
413
Rep Power
15
Not checked for errors and probably not too efficient:
Code:
```dim i as integer, j as integer, r as double
dim random(0 to LARGE_NUMBER) as double
for i=0 to LARGE_NUMBER
do:let r=rand()
for j=0 to i-1
if r=random(j) then exit for
next j
if j=i then
let random(i)=r
exit do
end if
loop
next i```