请参考以下程序。
Dim a() As Integer '声明一个用于存放产生随机数的动态数组
Dim StartN As Integer '随机数范围的起始数
Dim EndN As Integer '随机数范围的终止数
Dim RndN As Integer '存产生放随机数的个数
Dim i As Integer '循环变量
Dim S As String
StartN = Val(Text1.Text)
EndN = Val(Text2.Text)
RndN = Val(Text3.Text)
ReDim a(1 To RndN) '重定义数组
For i = 1 To RndN '循环RndRN次,产生RndN个随机数
a(i) = Int(Rnd * (EndN - StartN + 1)) + StartN
S = S & " " & a(i) '将产生的随机数用字符串的方式连接起来
Next
Label2.Caption = S
Dim myArray(19),myArray1(40)
For i=0 To 40
myArray1(i)=i
Next
Dim a,B,i,m
a=UBound(myArray)
B=UBound(myArray1)
Randomize
For i=0 To a
m=Int((B-i+1)*Rnd)
myArray(i)=myArray1(m)
For k=m To B-i-1
myArray1(k)=myArray1(k+1)
Next
Next
-------------------------------------------
这是我以前写的VBScript,[0,40]中取20个不重复数字到数组里,没写注释,你参考一下吧