T086学习网 | 站长学院 | 技术文档 | 成语 | 歇后语 | 帝国时代 | 代码收藏 | IP地址查询 | 生活百科 | 生日密码 | CSS压缩 | 用户评论 | 欣欣百宝箱

随机产生多个不重复数字的asp程序

【 本站原创作者:ITlearner 更新时间:2004-08-04 | 字体:
[导读]我们先来看一种我网上搜索到的程序: 随机产生4个不重复数字的asp程序!(上水道的)<%randomizedim a1,a2,a3,a4a1=Int(10 * Rnd)a2=Int(10 * Rnd)do while a1=a2a2=Int(10 * Rnd)loopa3=Int(10 * Rnd)do while a1=a...

我们先来看一种我网上搜索到的程序:

随机产生4个不重复数字的asp程序!(上水道的)
<%
randomize
dim a1,a2,a3,a4
a1=Int(10 * Rnd)
a2=Int(10 * Rnd)
do while a1=a2
a2=Int(10 * Rnd)
loop
a3=Int(10 * Rnd)
do while a1=a3 or a2=a3
a3=Int(10 * Rnd)
loop
a4=Int(10 * Rnd)
do while a1=a4 or a2=a4 or a3=a4
a4=Int(10 * Rnd)
loop
%>

<%=a1%>
<%=a2%>
<%=a3%>
<%=a4%>

挺好懂的,不过要是要生成多点数字,这样可就麻烦了,于是看到了下面一样写法:

--  作者:wxz
--  发布时间:2002-10-16 22:44:18

怎样一次生成10个不同的随机数
<%
dim n(10)
for i=1 to 10
Randomize
n(i)=Int(50* Rnd+1)
  for q=1 to i
    if n(i)=n(q-1) then
    n(i)=n(q)+1
    end if
  next
response.write n(i)&"<br>"
next
%>

总觉得这种方法很麻烦,但是找不到更好的方法了:(

那么我就利用此法写了一个通用的子函数。

<%
function showrnd(x,y)
if y<x then
 exit function
end if
redim n(x)
dim i,q
dim isok
for i=1 to 10
Randomize
n(i)=round((y-1)* Rnd)+1
isok=false
do while not isok
  for q=1 to i
    if n(i)=n(q-1) then
     n(i)=Int((y-1)* Rnd)+1
  isok=false
     exit for
 end if
  isok=true
  next
loop
response.write n(i)&"<br>"
next
end function

'产生在1到50内的10个随机数
call showrnd(10,50)
%>

  • 转载请注明来源:IT学习网 网址:http://www.t086.com/ 向您的朋友推荐此文章
  • 特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系我们,我们会尽快予以更正。
更多
留言建议ASP探针PHP探针站长Enjoy的Blog
© 2017 T086学习网 - T086.com(原itlearner.com)
RunTime:16.37ms QueryTime:7