【备忘】ASP数组随机排序

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

<%RandomizeDim m,n,MyArray(10),TempFor m = 0 to Ubound(MyArray)MyArray(m) = mNextFor n = 0 to Ubound(MyArray)RndNum = int(rnd*Ubound(MyArray))Temp = MyArray(n)MyArray(n) = MyArray(RndNum)MyArray(RndNum) = TempNextFor n = 0 to Ubound(MyArray)Response.Write MyArray(n) & "<br />"NextResponse.Write "-------------------<br />"'下边这种可以少写两行For m = 0 to Ubound(MyArray)MyArray(m) = mNextFor n = 0 to Ubound(MyArray)RndNum = int(rnd*(Ubound(MyArray)-n+1)+n)Temp = MyArray(n)MyArray(n) = MyArray(RndNum)MyArray(RndNum) = TempResponse.Write MyArray(n) & "<br />"Next%>

分享到微信

扫描二维码

可在微信查看或分享至朋友圈。

相关文章

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

召唤伊斯特瓦尔