Private Sub Command1_Click()'生成随机数字
Dim MyValue
Randomize ' 对随机数生成器做初始化的动作。
MyValue = Int((6 * Rnd()) + 1) ' 生成 1 到 7 之间(不包括7)的随机整数。
MsgBox MyValue
End Sub
Public Function 随机数(ByVal 位数 As Integer) As String '生成N位随机数字符串
Dim a As Integer
Dim b As Integer
Dim c As String
Dim d As String
c = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
For a = 1 To 位数
b = Int((Len(c) * Rnd) + 1)
d = d & Mid(c, b, 1)
Next
随机数 = d
End Function
Public Function 随机数2() As String '生成随机位随机数字符串
Dim a As Integer
Dim b As Integer
Dim c As String
Dim d As String
c = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
For a = 1 To Int((Len(c) * Rnd()) + 1)
b = Int((Len(c) * Rnd()) + 1)
d = d & Mid(c, b, 1)
Next
随机数2 = d
End Function
Public Function GetRnd(ByVal n As Integer) As String '获取N位随机小数
Randomize
Const Cstring As String = "1234567890"
GetRnd = Mid("0" & Rnd(1) & Cstring, 1, n + 2)
End Function