- 爱易网页
-
ASP教程
- 随机序列号,超菜,请
日期:2014-05-17 浏览次数:20911 次
随机序列号,超菜,请高手指点!
已经有这么一段随机序列号生成代码,
<script language=vbs>
function getRnd(min,max,num)
Dim myarr(),i,j
if num> max-min+1 or num <0 then
getRnd= "Error:num> max-min "
exit function
end if
redim myarr(num-1)
i=0
while i <num
Randomize
no = Int((max-min+1)*Rnd+min)
For j = 0 To i-1
If no = myarr(j) Then Exit For
Next
if j=i then
myarr(i) = no
i=i+1
End if
wend
getRnd=join(myarr, ", ")
end function
for i=1 to 100
document.write getRnd(10000000,900000000,1)& " <br> "
next
</script>
执行的时候显示的是100对随机数字,我想放置一个按钮,每点一下按钮生成一个数字,请问我该怎么写呢?
<form id= "form1 " name= "form1 " method= "post " action= " " >
<input type= "submit " name= "Submit " value= "生成随机序列号 " >
</form>
多谢大虾指点!
------解决方案--------------------
<script language=vbs>
function getRnd(min,max,num)
Dim myarr(),i,j
if num> max-min+1 or num <0 then
getRnd= "Error:num> max-min "
exit function
end if
redim myarr(num-1)
i=0
while i <num
Randomize
no = Int((max-min+1)*Rnd+min)
For j = 0 To i-1
If no = myarr(j) Then Exit For
Next
if j=i then
myarr(i) = no
i=i+1
End if
wend
getRnd=join(myarr, ", ")
end function
sub Submit_onclick
for i=1 to 100
document.write getRnd(10000000,900000000,1)& " <br> "
next
end sub
</script>