'length:产生的字符串的长度
public function random_number(length)
for gi=1 to length
randomize gi*cint(left(right(formatdatetime(now),5),2) & right(formatdatetime(now),2))
select case int(rnd*3)+1
case 1
randomize int(rnd*10)
gres=gres & chr(int(rnd*10)+48)
case 2
randomize int(rnd*26)
gres=gres & chr(int(rnd*26)+65)
case 3
randomize int(rnd*26)
gres=gres & chr(int(rnd*26)+97)
end select
next
random_number=gres
gres=""
end function
又一个生成随机字符
'####################
' 生成随机字符
'####################
Function makePassword(ByVal maxLen)
Dim strNewPass
Dim whatsNext, upper, lower, intCounter
Randomize
For intCounter = 1 To maxLen
whatsNext = Int((1 - 0 + 1) * Rnd + 0)
If whatsNext = 0 Then
'character
upper = 90
lower = 65
Else
upper = 57
lower = 48
End If
strNewPass = strNewPass & Chr(Int((upper - lower + 1) * Rnd + lower))
Next
makePassword = strNewPass
End Function
xbm.asp
----------------------------------------
<!--#include file="numcode.asp"-->
<%
Response.Buffer = True
With Response
.Expires = -1
.AddHeader "Pragma","no-cache"
.AddHeader "cache-ctrol","no-cache"
End With
Dim num
Randomize
num = Int(7999 * Rnd + 2000)
Session("validateCode") = num
Dim Image
Dim Width, Height
Dim digtal
Dim Length
Dim sort
Dim hc
Length = 4
hc = chr(13) & chr(10)
Redim sort(Length)
digital = ""
For I = 1 To Length - Len(num)
digital = digital & "0"
Next
For I = 1 To Len(num)
digital = digital & Mid(num, I, 1)
Next
For I = 1 To Len(digital)
sort(I) = Mid(digital, I, 1)
Next
Width = 8 * Len(digital)
Height = 10