找回密码
 注册
搜索
查看: 1278|回复: 1

ASP随机生成汉字

[复制链接]
发表于 2009-6-23 22:04:19 | 显示全部楼层 |阅读模式
  1. <%Dim i
  2. Dim j
  3. Dim HS
  4. Dim HE
  5. Dim LS
  6. Dim LE
  7. dim Result
  8. Result=""
  9. HS = 177
  10. HE = 247
  11. LS = 161
  12. LE = 254
  13. dim Max_Num
  14. Max_num=65536
  15. Randomize
  16. For i = 1 To 4
  17. temp1=dec2bin(Int((HE - HS) * Rnd()) + HS)
  18. temp2=dec2bin(Int((LE - LS) * Rnd()) + LS)
  19. Result = Result & chr(BinaryToDecimal(temp1 & temp2) - Max_num)

  20. Next
  21. response.write Result & " "
  22. %>
  23. <%
  24. ''下面是函数
  25. ''-------------------------------------------
  26. Public Function dec2bin(mynum)''十进制到二进制
  27. Dim loopcounter
  28. If mynum >= 2 ^ 31 Then
  29. dec2bin = "Too big"
  30. Exit Function
  31. End If
  32. Do
  33. If (mynum And 2 ^ loopcounter) = 2 ^ loopcounter Then
  34. dec2bin = "1" & dec2bin
  35. Else
  36. dec2bin = "0" & dec2bin
  37. End If
  38. loopcounter = loopcounter + 1
  39. Loop Until 2 ^ loopcounter > mynum
  40. End Function
  41. ''-------------------------------------------
  42. Public Function BinaryToDecimal(BinaryValue) ''二进制到十进制的转换
  43. '' Returns the decimal equivalent of a binary number
  44. Dim idx
  45. Dim tmp
  46. Dim result
  47. Dim digits
  48. digits = Len(BinaryValue)
  49. For idx = digits To 1 Step -1
  50. tmp = Mid(BinaryValue, idx, 1)
  51. If tmp = "1" Then result = result + 2 ^ (digits - idx)
  52. Next
  53. BinaryToDecimal = result

  54. End Function
  55. %>
复制代码
发表于 2010-2-22 19:13:50 | 显示全部楼层
知道了 不错~~~  
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|QQ客服|联系我们|Archiver|手机版|小黑屋|悉远网络 ( 鄂ICP备09013446号 )

GMT+8, 2024-11-21 18:36 , Processed in 0.039657 second(s), 7 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表