考试试题库的随机提取问题的解决。
大可山人 博客专家认证 2003-05-16 07:38:56 一朋友问道考试题的随机提取问题:欲从考题数据库中随机提取一定数量的考题,如何做?
现将我的结果贴出来,希望对有类似问题的网友有用。
----------------------------------------------
n为试题库总数量,m为欲取出的试题数量。
最后的结果为从小到大依次排序。
注意:m<=n(不是废话的废话!)
<%
'作者:朱继山 zjs@dagongbao.com
'关键字:随机数
const n=100,m=10
dim k,p,tp,i
For k=0 to 100000
Randomize
p=fix(rnd*n)+1
if Not instr(tp,p)>0 then
tp=tp & p & ","
i=i+1
end if
if i>=m then exit for
Next
dim t
t=split(tp,",")
for k=0 to m-1
for j=0 to m-1
if Cint(t(k))>Cint(t(j)) and k<j then
temp=t(j)
t(j)=t(k)
t(k)=temp
end if
next
Next
dim r
r=join(t,",")
response.write r
%>