(急!)从3000个常用汉字中随机生成3个字的程序应该怎么写?3个字可重复出现。

如题所述

把这3000个常用汉字贴到记事本中,汉字之间不留空格,不换行。保存为"d:\1.txt"。
再运行下面的程序即可:

Private Sub Command1_Click()
Dim a As String
Open "d:\1.txt" For Input As #1
Line Input #1, a
For i = 1 To 3
t = Int(Rnd() * 3000 + 1)
Print Mid(a, t, 1);
Next i
Print
Close #1
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-03-17
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

Private Sub Command1_Click()
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 3
temp1 = dec2bin(Int((HE - HS) * Rnd()) + HS)
temp2 = dec2bin(Int((LE - LS) * Rnd()) + LS)
result = result & Chr(BinaryToDecimal(temp1 & temp2) - Max_Num)
Next
Me.Print result & " "
End Sub
相似回答