可用的ASP无重复数字随机函数, 数组实现, 并应用于随机显示记录集

所属分类: 网络编程 / ASP编程 阅读数: 984
收藏 0 赞 0 分享
经脚本之家站长测试可用的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)  
%> 
更多精彩内容其他人还在看

ASP 指南

ASP 指南
收藏 0 赞 0 分享

改进 ASP 的字符串处理性能

改进 ASP 的字符串处理性能
收藏 0 赞 0 分享

pjblog2的参数第1/2页

pjblog2的参数
收藏 0 赞 0 分享

ASP智能搜索的实现

ASP智能搜索的实现
收藏 0 赞 0 分享

网站生成静态页面攻略2:数据采集

网站生成静态页面攻略2:数据采集
收藏 0 赞 0 分享

网站生成静态页面攻略3:防采集策略

网站生成静态页面攻略3:防采集策略
收藏 0 赞 0 分享

网站生成静态页面攻略4:防采集而不防搜索引擎策略

网站生成静态页面攻略4:防采集而不防搜索引擎策略
收藏 0 赞 0 分享

简单分页函数一 常用

简单分页函数一 常用
收藏 0 赞 0 分享

asp最常用的分页函数

asp最常用的分页函数
收藏 0 赞 0 分享

LINE9的目录浏览源程序

LINE9的目录浏览源程序
收藏 0 赞 0 分享
查看更多