saintom 发表于 2003-11-6 23:16:54

生成随机字符串

<%@ LANGUAGE = VBScript %>
<html>
<title>
生成随机字符串
</title>
<body>
<%
Function gen_key(digits)
&#39;定义并初始化数组
    dim char_array(80)
        &#39;初始化数字
    For i = 0 To 9
      char_array(i) = CStr(i)
    Next
        &#39;初始化大写字母
    For i = 10 To 35
      char_array(i) = Chr(i + 55)
    Next
        &#39;初始化小写字母
    For i = 36 To 61
      char_array(i) = Chr(i + 61)
    Next
        Randomize   &#39;初始化随机数生成器。
        do while len(output) < digits
      num = char_array(Int((62 - 0 + 1) * Rnd + 0))
      output = output + num
    loop
&#39;设置返回值
    gen_key    =    output
End Function
&#39;把结果返回给浏览器
response.write "本实例生成的 5位随机字符串为:"
response.write "<center>"
response.write gen_key(5)
response.write "</center>"
%>
</body>
</html>
页: [1]
查看完整版本: 生成随机字符串