ASP随机生成汉字的方法

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>ASP随机生成汉字的方法</title>

</head>

<body>

<%Dim i

    Dim j

    Dim HS

    Dim HE

    Dim LS

    Dim LE

    dim Result

    Result=""

    HS = 177

    HE = 247

    LS = 161

    LE = 254

    dim Max_Num

    Max_num=65536

    Randomize   

    For i = 1 To 4 

temp1=dec2bin(Int((HE - HS) * Rnd()) + HS) 

temp2=dec2bin(Int((LE - LS) * Rnd()) + LS) 

        Result = Result & chr(BinaryToDecimal(temp1 & temp2) - Max_num)

    Next

    response.write Result & " "

%>

<%

    ''下面是函数

''-------------------------------------------

Public Function dec2bin(mynum)''十进制到二进制

Dim loopcounter 

If mynum >= 2 ^ 31 Then

dec2bin = "Too big"

Exit Function

End If

Do

If (mynum And 2 ^ loopcounter) = 2 ^ loopcounter Then

dec2bin = "1" & dec2bin

Else

dec2bin = "0" & dec2bin

End If

loopcounter = loopcounter + 1

Loop Until 2 ^ loopcounter > mynum

End Function

''-------------------------------------------

Public Function BinaryToDecimal(BinaryValue) ''二进制到十进制的转换

'' Returns the decimal equivalent of a binary number

Dim idx

Dim tmp

Dim result

Dim digits

digits = Len(BinaryValue)

For idx = digits To 1 Step -1    

    tmp = Mid(BinaryValue,idx,1)

    If tmp = "1" Then result = result + 2 ^ (digits - idx)

Next

BinaryToDecimal = result

End Function 

%>

</body>

</html>

相关文章

数组的定义 Dim MyArray MyArray = Array(1‚5‚123‚12‚98...
\'参数: \'code:要检测的代码 \'leixing:html或者ubb \'n...
演示效果: 代码下载: 点击下载
环境:winxp sp2 ,mysql5.0.18,mysql odbc 3.51 driver 表采...
其实说起AJAX的初级应用是非常简单的,通俗的说就是客户端(j...
<% ’判断文件名是否合法 Function isFilename(aFilename...