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
参考资料:http://www.haishui.net/view.php?id=454 set rs=server.CreateObject("adodb.recordset")
sql="select * from 表"
rs.open sql,conn,1,3'打开数据库表
i=1
dim webon()
do while not rs.Eof'写入数组
Redim Preserve webon(i)
webon(i)=rs("id")
i=i+1
rs.movenext
loop