可用的ASP無重複數字隨機函數, 數組實現, 並應用於隨機顯示記錄集_應用技巧

來源:互聯網
上載者:User
經雲棲社區站長測試可用的ASP無重複數字隨機函數, 數組實現, 並應用於隨機顯示記錄集
作用:
本函數適用於隨機顯示小數量的隨機不重複數字
本函數適用於顯示小數量的隨機不重複記錄集
為了不影響效率, 上限超過一千, 不建議使用本函數
shawl.qiu
2006-09-06
 http://blog.csdn.net/btbtd
主內容: 函數及應用函數隨機顯示100條記錄
linenum 
複製代碼 代碼如下:

<%  
    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 無重複數字隨機函數, 數組實現, By shawl.qiu  
    ' 2006-09-06  
    '   http://blog.csdn.net/btbtd  
    '''''''''''''''''''''''''''''''''  
    ' 注意: 隨機數超過1000, 不建議使用本函數.  
    '''''''''''''''''''''''''''''''''  
    ' 參數說明:  
    '''''''''''''''''''''''''''''''''  
    ' lwNum 為 數字數組下限, 如: 1  
    ' upNum 為 數字數組上限, 如: 100  
    '''''''''''''''''''''''''''''''''  
    ' sample call:  
    '''''''''''''''''''''''''''''''''  
    '    dim t  
    '    for each t in fRndNoRpt(1,100)  
    '        response.write t&"<br/>"  
    '    next  
    ''''''''''''''''''''''''''''''''''''''''''''  
        if upNum<1 or isNull(upNum) or upNum="" or isNumeric(upNum)=false then exit function  
        if lwNum<0 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/>使用隨機數函數顯示1至100的不重複隨機數 1:<br/>-----------------------<br/>"  
    for each temp in fRndNoRpt(1,100)  
        response.write temp&"<br/>"  
    next  
    response.write "<p/>使用隨機數函數顯示1至100的不重複隨機數 2:<br/>-----------------------<br/>"  
    temp=join(fRndNoRpt(1,100),"-")  
    response.write mid(temp,1,len(temp)-1)  
%> 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.