当前位置: 首页 > 图文教程 > 网络编程 > ASP > 可用的ASP无重复数字随机函数, 数组实现, 并应用于随机显示记录集

ASP
asp数个使用技巧
存储过程里的递归 实现方法
非常不错的列出sql服务器上所有数据库的asp代码
防范ASP木马的十大基本原则强列建议看下
雷客图ASP站长安全助手的ASP木马查找功能
防止别人盗链的好方法推荐
图片的入库与读取的方法
用asp实现无组件生成验证码的方法2种
用asp实现检测文件编码
[asp]怎么添加验证码的解决方法
ASP文章系统解决方案实现上一页下一页
ASP编程入门进阶(三):接触脚本程序
ASP编程入门进阶(四):内置对象Request
ASP编程入门进阶(五):内置对象Response
ASP编程入门进阶(六):Cookies讲座
ASP编程入门进阶(八):内置对象Session
ASP编程入门进阶(九):内置对象Application
ASP编码优化技巧8则
ASP编程入门进阶(十):Global.asa文件
ASP编程入门进阶(十一):Chat聊天程序

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 60 ::
收藏到网摘: n/a

经软晨学习网站长测试可用的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)
%>