function rndarray(istart,iend,sum)
'istart和iend是数的开始和结束 sum是你要输出数的个数
dim arrayid(),i,j,blnre,temp,iloop,eloop
redim arrayid(sum-1)
i=0
iloop=0
eloop=0
blnre=false
randomize
do while i<sum
temp=int(rnd*(iend-istart+1)+istart)
if i=0 then
arrayid(0)=temp
i=i+1
iloop=iloop+1
else
for j=0 to i-1
if arrayid(j)=temp then
blnre=true
iloop=iloop+1
exit for'这一句很重要,防止多余的循环
else
iloop=iloop+1
end if
next
if blnre=false then
arrayid(i)=temp
i=i+1
else
blnre=false
end if
end if
eloop=eloop+iloop
iloop=0
loop
rndarray=join(arrayid)&"循环次数:"&eloop
end function
response.write rndarray(0,100,6)&"<br>"'调用过程