效率比较高的抽题算法(asp考试系统)

以抽取选择题为例。根据科目不同抽题组卷,没有增加根据题目难度抽题的条件。

dim q_all()'所有试题数组
dim q_number'要抽取试题数
dim q_select()'抽取完成的试题存放数组
dim j
dim t_sunum '试卷科目数
dim t_qunum()'这个科目的试题数 
dim t_suid()'科目id
dim k
dim selbegin'当前已选题数
dim selend'当前应选试题结束数
dim single_num'单选题试题总数

single_num=0
 selnum=1
 selbegin=0
 t_sunum=0
 q_number=0
 selend=0
    '试卷所包含科目及科目试题数
   set resbuff=server.CreateObject("adodb.recordset")
    strsql="select * from k_temp_relation where k_t_r_examid="&cint(session("exam")) &" and k_t_r_type=1 "'查出试卷所有包含试题科目的信息
   resbuff.open strsql,conn,1,1
   if err.number <> 0 then
       response.write "数据库操作失败:"&err.description
     response.redirect"error.htm"
    else
      if not resbuff.eof and not resbuff.bof  then
       t_sunum=resbuff.RecordCount'获得包含所有科目
     redim  t_suid(t_sunum)
        redim  t_qunum(t_sunum)
        resbuff.movefirst
      for i=1 to t_sunum
        t_suid(i)=resbuff("k_t_r_suid")
     t_qunum(i)=resbuff("k_t_r_num")
     single_num=single_num+cint(t_qunum(i))
        resbuff.movenext
      next
   end if
   end if
 set resbuff=nothing
  redim q_select(single_num)'定义单选题的总数

 '抽题过程
for  k=1 to t_sunum
   set resbuff=server.CreateObject("adodb.recordset")
    strsql="select k_q_id from k_question where k_q_subjectid="&cint( t_suid(k)) & " and k_q_type=1  "'查询出所有符合条件的试题,从中随机抽取。
   resbuff.open strsql,conn,1,1
   if err.number <> 0 then
       response.write "数据库操作失败:"&err.description
     response.redirect"error.htm"
    else
      if not resbuff.eof and not resbuff.bof  then
       q_number=resbuff.RecordCount'获得科目所有试题
       redim  q_all(q_number)
       resbuff.movefirst
    for i=1 to q_number
       q_all(i)=resbuff("k_q_id")
       resbuff.movenext
    next
   end if
   end if
 set resbuff=nothing
 '随机抽取所有试题中的指定数目试题
  randomize
 
  selend=t_qunum(k)+selbegin
 
   for i=selbegin+1 to selend
    temp=int(q_number*rnd+1)
    q_select(i)=q_all(temp)
    q_number=q_number-1
      for j=temp to q_number
         q_all(j)=q_all(j+1)
      next  
  next
  selbegin=selend '一个科目抽题结束,将最后抽题数设为下一科目抽题数开始
 
next '所有科目抽题结束

评论 (0) |  固定链接 |  类别 ( 软件设计) | 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值