2,462
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Sub test()
Dim iDic As New Dictionary, w1 As String, ww
Randomize ''随机初始化
''红色球1-33任意取6个
Do
w1 = Format$(CInt(Rnd * 33) + 1, "0#")
If Not iDic.Exists(w1) Then iDic(w1) = "0"
If iDic.Count = 6 Then Exit Do
Loop
''蓝色球取1个
w1 = Format$(Int(Rnd * 16) + 1, "0#")
''输出
Debug.Print Join(iDic.Keys, ",") & "--" & w1
iDic.RemoveAll ''清空字典
End Sub
Private Sub Command1_Click()
Dim sOut As String
Dim aBuf() As Long, SUM As Long
Dim i As Long, t As Long
SUM = 32: ReDim aBuf(SUM)
For i = 0 To SUM
aBuf(i) = i + 1
Next
Randomize: sOut = ""
For i = 1 To 6 ' 红色球
t = SUM * Rnd
sOut = sOut & Right$("0" & aBuf(t), 2) & " "
aBuf(t) = aBuf(SUM)
SUM = SUM - 1
Next
sOut = sOut & Right$("0" & CInt(1 + 15 * 0.98), 2)
MsgBox sOut
End Sub