【备忘】ASP数组随机排序

  将数组随机排序,或者说输出N个不重复的随机数,

<%
Randomize
Dim m,n,MyArray(10),Temp
For m = 0 to Ubound(MyArray)
    MyArray(m) = m
Next
For n = 0 to Ubound(MyArray)
    RndNum = int(rnd*Ubound(MyArray))
    Temp = MyArray(n)
    MyArray(n) = MyArray(RndNum)
    MyArray(RndNum) = Temp
Next
For n = 0 to Ubound(MyArray)
    Response.Write MyArray(n) & "<br />"
Next

Response.Write "-------------------<br />"
'下边这种可以少写两行

For m = 0 to Ubound(MyArray)
    MyArray(m) = m
Next
For n = 0 to Ubound(MyArray)
    RndNum = int(rnd*(Ubound(MyArray)-n+1)+n)    
    Temp = MyArray(n)
    MyArray(n) = MyArray(RndNum)
    MyArray(RndNum) = Temp
    Response.Write MyArray(n) & "<br />"
Next
%>

原文链接:http://www.wdssmq.com/post/20130902595.html

分享本文:新浪微博腾讯微博

神来一句:

  • [贱人就是矫情]
  • [人艰不拆]
  • [朕知道了]
  • [不明觉厉]
  • [这真是极好的]
  • [也真是醉了]
  • [点个赞]
  • [你那么萌你家人造吗?]
  • [涨姿势!]
赞助一下
Baidu Button BEGIN
分享