Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to pick 5 different numbers between a range

Status
Not open for further replies.

QAteste

Technical User
Jun 14, 2002
23
US
New to VB. Any help is much appreciated. Is there a better way to do this?

-------------------------
cnt = 4
dim tryArray(4)

' First I pick 5 numbers
for x = 0 to cnt
Randomize
tryArray(x) = (Cint(((intCnt-1)-0+1) * Rnd+0)
Next

' Then I go through comparing each one to each other
' making sure they are all unique
For y = 0 to cnt
For z = 0 to cnt
' If one matches another, get another number and
' start the checks all over again
if tryArray(y) = tryArray(z) AND y<>z then
Randomize
tryArray(z) = (Cint(((intCnt-1)-0+1) * Rnd+0)
y=-1
z=0
Exit For
End if
Next
Next
-------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top