asp資料庫隨機-ag真人国际官网
『壹』 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("
("&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