| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 775 人关注过本帖
标题:这段产生随机数的代码,怎样才能让随机数不重复?
只看楼主 加入收藏
dhdhzzw
Rank: 1
等 级:新手上路
帖 子:949
专家分:0
注 册:2007-8-13
结帖率:81.82%
收藏
 问题点数:0 回复次数:1 
这段产生随机数的代码,怎样才能让随机数不重复?
<%
Function gen_key(digits)

dim char_array(50)
char_array(0) = "0"
char_array(1) = "1"
char_array(2) = "2"
char_array(3) = "3"
char_array(4) = "4"
char_array(5) = "5"
char_array(6) = "6"
char_array(7) = "7"
char_array(8) = "8"
char_array(9) = "9"
char_array(10) = "A"
char_array(11) = "B"
char_array(12) = "C"
char_array(13) = "D"
char_array(14) = "E"
char_array(15) = "F"
char_array(16) = "G"
char_array(17) = "H"
char_array(18) = "I"
char_array(19) = "J"
char_array(20) = "K"
char_array(21) = "L"
char_array(22) = "M"
char_array(23) = "N"
char_array(24) = "O"
char_array(25) = "P"
char_array(26) = "Q"
char_array(27) = "R"
char_array(28) = "S"
char_array(29) = "T"
char_array(30) = "U"
char_array(31) = "V"
char_array(32) = "W"
char_array(33) = "X"
char_array(34) = "Y"
char_array(35) = "Z"

randomize

do while len(output) < digits
num = char_array(Int((35 - 0 + 1) * Rnd + 0))

output = output + num
loop


gen_key = output
End Function


response.write "<pre>" & gen_key(13) & "</pre>" & vbcrlf
response.write "<pre>" & gen_key(14) & "</pre>" & vbcrlf
%> 
想让他生成的数组不重复,有什么好的办法?
搜索更多相关主题的帖子: 随机数 代码 
2008-01-15 13:54
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
’获得一定长度的随机数代码
’参数max最大长度
’参数min最小长度
Function getRanDom(max,min)
    Dim times, i, j times = 2
    Dim ttNumber
    ttNumber = max + min - 1
    Dim tAry()
    ReDim tAry(ttNumber)
    For i = 0 To ttNumber
        tAry(i) = min + i
    Next
    For j = 0 To times - 1
        i = ttNumber - 1
        While i > 0
              Dim temp,
              randomNum temp = 0
              randomNum = CInt(TtGetRandom(0, max * 3, i) Mod i)              temp = tAry(i)
              tAry(i) = tAry(randomNum)
              tAry(randomNum) = temp i = i - 1
       Wend
   Next
   getRanDom = tAry
End Function
Function TtGetRandom(max,min,chaosSeed)
    Randomize chaosSeed * Timer()
    TtGetRandom = Rnd * chaosSeed
End Function
'获得5位无重复随机数
Dim RndNum
RndNum=getRanDom(5,1)
Response.Write RndNum
2008-01-15 16:38
快速回复:这段产生随机数的代码,怎样才能让随机数不重复?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016676 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved