如何随机调用试题库中的50条不重复的记录,
我现在用asp和access开发一个网上考试系统,试题库里有上千条试题记录,我想在用户登陆以后从试题库里随机(难点:随机)调出50道题目,不知道大家有没有高效快捷的方法,主要是如何实现asp代码和sql。试题的id号不一定是连续的,可以实现吗?
网上有现成的代码下载吗或者是参考样本,程序流程呢,不胜感激。
---------------------------------------------------------------
<%
dim sql,rs,nowid,newidstr,loopnum,idarr,i
''初始化随机函数
randomize
''从数据库中读取记录
sql="select * from yourtable"
rs.open sql,conn,1,1
if not rs.eof then
rscount=rs.recordcount
end if
rs.close
set rs=nothing
''随机ID函数
function getid()
do while loopnum<50
nowid=int(rnd()*rscount))
if instr(newidstr,nowid)>1 then
call getid()
else
newidstr=newidstr & ","&nowid
loopnum=loopnum+1
end if
loop
end function
''分解newidster,取得不相同的ID号
idarr=split(newidstr,",")
for i=0 to ubound(idarr)-1
sql="select * from yourtable where id="&idarr(i)
显示语句在这里写
next
网上有现成的代码下载吗或者是参考样本,程序流程呢,不胜感激。
---------------------------------------------------------------
<%
dim sql,rs,nowid,newidstr,loopnum,idarr,i
''初始化随机函数
randomize
''从数据库中读取记录
sql="select * from yourtable"
rs.open sql,conn,1,1
if not rs.eof then
rscount=rs.recordcount
end if
rs.close
set rs=nothing
''随机ID函数
function getid()
do while loopnum<50
nowid=int(rnd()*rscount))
if instr(newidstr,nowid)>1 then
call getid()
else
newidstr=newidstr & ","&nowid
loopnum=loopnum+1
end if
loop
end function
''分解newidster,取得不相同的ID号
idarr=split(newidstr,",")
for i=0 to ubound(idarr)-1
sql="select * from yourtable where id="&idarr(i)
显示语句在这里写
next
浙公网安备 33010602011771号