asp 随机读取数据库

Set rs = Server.CreateObject("Adodb.RecordSet")
  rs.open sql,conn,1,1
  DIM Appeared
  Call DisRndRecord(10,rs.recordCount)'调用函数该位置显示记录
  '################SUBS################
  '#DisRndRecord(DisNum,rsBound)
  '#参数DisNum:显示数量
  '#参数rsBound:随机数产生范围
  Sub DisRndRecord(DisNum,rsBound)
  DIM i,ThisRnd
  If rsBound < DisNum Then DisNum = rsBound'记录总数小于要抽取记录条数的情况
  For i = 0 To DisNum - 1
  ThisRnd = GetRnd(rsBound)'取得一个不重复的随机数
  rs.Move(ThisRnd)'游标移动到随机数位置数读取
  Response.Write("<br/>("&rs("id")&")"&rs("Title"))
  rs.Move(-ThisRnd)
  Next
  End Sub
  '# 函数GetRnd(bound)返回一个不重复的随机数字
  '#参数bound:随机范围
  Function GetRnd(bound)
  DIM ranNum
  Randomize()
  ranNum=int(bound*rnd)
  If Instr(Appeared,"["&ranNum&"]") Then '产生的随机数是否出现过
  ranNum = getRnd(bound)
  End If
  Appeared = Appeared & "["&ranNum&"]" '记录已出现的随机数
  GetRnd = ranNum
  End Function

你可能感兴趣的:(读取数据)