0 Then i = i - 1 Else strreValue = strreValue & reValue & "," End If Next strreValue = left(strreValue,len(strreValue) - 1) strreValue = Replace(strreValue,",","",1,1) GetrndNumber = strreValueEnd Function%>[/code]获取随机数以后,如果还需要从小到大或者从大到小排序,你可以参阅本站另外一篇关于排序的函数的文章常用的几种asp排序方法介绍 [url]http://yty.cc/article.asp?id=522[/url]这里我也提供和上面函数相关的排序例子:[code] Cint(a_Data(j)) Then '这里的大于>如果改成小于" & str & ":" For i = 0 To UBound(a_Data) s = s & a_Data(i) & "," Next s = Left(s, Len(s)-1) Response.Write s Response.Write ""End Sub%>[/code], - 三思随然 - 主动即自由,阅历即财富!简简单单,一切随然!" /> 用ASP获取指定范围内的一组不重复的随机整数 - 三思随然

用ASP获取指定范围内的一组不重复的随机整数


该ASP函数可以获取指定范围内的一组不重复的随机整数,具体调用方法请查看说明。
<%
'调用方法:
'获取10个1到100之间的整数
Response.Write GetrndNumber(1,100,10)

Function GetrndNumber(intStart,intEnd,intCount)
     Rem 取指定范围内不同的随机整数
     Rem intStart:起始值
     Rem intEnd:结束值
     Rem intCount:值个数
     Rem no_mIss
     Rem 调用:GetrndNumber(1,9,5)
     On error resume next
     Dim i,reValue,strreValue
     reValue = "" : strreValue = ","
     If Not isNumeric(intStart) or Not isNumeric(intEnd) _
           or Not isNumeric(intCount)  Then Response.write "参数错误!" : Response.End
     If intCount>(intEnd - intStart)+1 Then Response.write "参数错误!" : Response.End
     randomize
     For i = 0 to intCount - 1
           reValue = Int((intEnd - intStart + 1) * Rnd + intStart)
           If instr(strreValue,"," & reValue & ",")>0 Then
                 i = i - 1
           Else
                 strreValue = strreValue & reValue & ","
           End If
     Next
     strreValue = left(strreValue,len(strreValue) - 1)
     strreValue = Replace(strreValue,",","",1,1)
     GetrndNumber = strreValue
End Function
%>


获取随机数以后,如果还需要从小到大或者从大到小排序,你可以参阅本站另外一篇关于排序的函数的文章
常用的几种asp排序方法介绍 http://yty.cc/article.asp?id=522

这里我也提供和上面函数相关的排序例子:
<%
'获取10个1到100之间的整数
RndStr=GetrndNumber(1,100,10)  '这个函数在上面的例子中,你可以把上面的函数拷贝到这里来
Response.Write RndStr
Dim aData
aData = split(RndStr,",")
Call ResponseArray(QuickSort(aData),"从小到大排序")

Function QuickSort(a_Data)
    Dim i, j
    Dim bound, t
    bound = UBound(a_Data)

    For i = 0 To bound-1
        For j = i+1 To bound
            If Cint(a_Data(i)) > Cint(a_Data(j)) Then '这里的大于>如果改成小于< 则按照从大到小排序
                t = a_Data(i)
                a_Data(i) = a_Data(j)
                a_Data(j) = t
            End If
        Next
    Next

    QuickSort = a_Data
End Function

'输出数组
Sub ResponseArray(a_Data, str)
    Dim s
    s = ""
    Response.Write "<b>" & str & ":</b>"
    For i = 0 To UBound(a_Data)
        s = s & a_Data(i) & ","
    Next
    s = Left(s, Len(s)-1)
    Response.Write s
    Response.Write "<hr>"
End Sub
%>


[本日志由 随然 于 2009-07-04 10:59 PM 编辑]
上一篇: ASP实现access随机显示不重复记录解决方案
下一篇: IIS 上传文件大小配置步骤(默认200K) 和metabase.xml 修改不了的问题
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: ASP 代码 函数
相关日志:
评论: 0 | 引用: 0 | 查看次数: 13435
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1 字 | UBB代码 关闭 | [img]标签 关闭