请教如何在给定的几个数中随机选出3个数?

lio_sy 2003-09-12 11:19:07
最好是ASP的!·
...全文
357 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lions911 2003-09-12
  • 打赏
  • 举报
回复
<SCRIPT LANGUAGE="Vbscript">
Option Explicit
dim n,result
'//原数
n = "21,5,13,7,11,8,2"
'//结果
result = rndNumber(n,3)
'//Print
document.write result

function rndNumber(o,count)
Randomize
Dim result,r,i
o = split(o,",")
While len(result) < count*3
r = int(rnd*(Ubound(o)+1))
if Instr(result,","&o(r)&",") < 1 then
result = result & "," & o(r) & ","
end if
Wend
result = mid(result,2,len(result)-2)
result = replace(result,",,",",")
rndNumber = result
end function
</SCRIPT>
============================================


randomize

dim a(),b()
dim i,j,m
redim a(7)
redim b(3)

a(0)=21
a(1)=5
a(2)=13
a(3)=7
a(4)=11
a(5)=8
a(6)=2
b(0)=a(int(rnd*6))

for i=1 to 2
m=a(int(rnd*6))
if b(i)=m then
i=i-1
else
b(i)=m
end if
next

'数组b()中的元素就是随机选出的3个数

10,606

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧