經(jīng)腳本之家站長測試可用的ASP無重復(fù)數(shù)字隨機(jī)函數(shù), 數(shù)組實現(xiàn), 并應(yīng)用于隨機(jī)顯示記錄集
作用:
本函數(shù)適用于隨機(jī)顯示小數(shù)量的隨機(jī)不重復(fù)數(shù)字
本函數(shù)適用于顯示小數(shù)量的隨機(jī)不重復(fù)記錄集
為了不影響效率, 上限超過一千, 不建議使用本函數(shù)
shawl.qiu
2006-09-06
http://blog.csdn.net/btbtd
主內(nèi)容: 函數(shù)及應(yīng)用函數(shù)隨機(jī)顯示100條記錄
linenum
復(fù)制代碼 代碼如下:
%
dim rs, rNum
dim temp
set rs=createObject("adodb.recordset")
rs.open "select top 100 * from rnd_v1",conn,1
rNum=rs.recordCount-1
for each temp in fRndNoRpt(0,rNum)
rs.move temp
response.write rs("sbcat")
response.write "br/>"
rs.movefirst
next
rs.close
set rs=nothing 'shawl.qiu code'
function fRndNoRpt(lwNum,upNum)
''''''''''''''''''''''''''''''''''''''''''''
' ASP 無重復(fù)數(shù)字隨機(jī)函數(shù), 數(shù)組實現(xiàn), By shawl.qiu
' 2006-09-06
' http://blog.csdn.net/btbtd
'''''''''''''''''''''''''''''''''
' 注意: 隨機(jī)數(shù)超過1000, 不建議使用本函數(shù).
'''''''''''''''''''''''''''''''''
' 參數(shù)說明:
'''''''''''''''''''''''''''''''''
' lwNum 為 數(shù)字?jǐn)?shù)組下限, 如: 1
' upNum 為 數(shù)字?jǐn)?shù)組上限, 如: 100
'''''''''''''''''''''''''''''''''
' sample call:
'''''''''''''''''''''''''''''''''
' dim t
' for each t in fRndNoRpt(1,100)
' response.write t"br/>"
' next
''''''''''''''''''''''''''''''''''''''''''''
if upNum1 or isNull(upNum) or upNum="" or isNumeric(upNum)=false then exit function
if lwNum0 or isNumeric(lwNum)=false then exit function
dim num, temp
dim ar()
redim ar(upNum)
dim j:j=0
for temp=lwNum to upNum
num=num"."temp"."
next
randomize
do until num=""
temp=int((upNum-lwNum+1)*rnd+lwNum)
if inStr(num,"."temp".")>0 then
num=replace(num,"."temp".","")
ar(j)=temp
j=j+1
end if
loop
fRndNoRpt=ar
erase ar
end function 'shawl.qiu code'
response.write "p/>使用隨機(jī)數(shù)函數(shù)顯示1至100的不重復(fù)隨機(jī)數(shù) 1:br/>-----------------------br/>"
for each temp in fRndNoRpt(1,100)
response.write temp"br/>"
next
response.write "p/>使用隨機(jī)數(shù)函數(shù)顯示1至100的不重復(fù)隨機(jī)數(shù) 2:br/>-----------------------br/>"
temp=join(fRndNoRpt(1,100),"-")
response.write mid(temp,1,len(temp)-1)
%>