7月2

ASP生成指定范围内指定个数不重复随机数

| |
16:21 ASP  From: 本站原创
ASP生成指定范围内指定个数不重复随机数

<%
'生成10个7到30间的不重复随机数
response.write RandomizeNum(10,7,30)
%>
<%
'生成规定范围内的多个不重复数字
Function  RandomizeNum(count,lownum,highnum)
  If  highnum<count then
    exit function
  End If
  redim n(count)
  Dim  i,q
  Dim  isok
  For i=1 to count
    Randomize
    n(i)=round((highnum-lownum)* Rnd)+lownum
    isok=false
    Do  while not isok
      For q=1 to i
        If n(i)=n(q-1) then
          n(i)=Int((highnum-lownum)* Rnd)+lownum
          isok=false
          exit for
        End If
        isok=true
      Next
    Loop
    If i=count Then
      RandomizeNum = RandomizeNum& n(i)
    Else
      RandomizeNum = RandomizeNum & n(i) &","            
    End If
  Next
end Function
%>

最后编辑: tommyhu 编辑于2011/07/02 16:41
阅读(1772) | 评论(0) | 引用(0)
在此留下酱油瓶-:)
表情
emotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我

您的大名(例如:小明) : 

密码(可不填) :  游客无需密码

网址 (可不填) : 

电邮 (可不填) :  [注册]