一个Command,一个Label
Dim RedBalls, BullBalls
Private Sub Command1_Click()
Label1.Caption = ""
rarr = GetRndNotRepeat(0, UBound(RedBalls), 6)
barr = GetRndNotRepeat(0, UBound(BullBalls), 1)
For i = 1 To 6
t = Now
Do
DoEvents
Loop While DateDiff("s", t, Now) < 1
Label1.Caption = Label1.Caption & "(" & Format(RedBalls(rarr(i)), "00") & ")"
Next i
Label1.Caption = Label1.Caption & "|"
t = Now
Do
DoEvents
Loop While DateDiff("s", t, Now) < 1
Label1.Caption = Label1.Caption & "(" & Format(BullBalls(barr(1)), "00") & ")"
End Sub
Private Sub Form_Load()
RedBalls = Array(2, 3, 4, 7, 8, 9, 12, 13, 14, 17, 18, 19, 22, 23, 24, 27, 28, 29, 32, 33)
BullBalls = Array(3, 4, 5, 9, 13, 14, 15)
End Sub
Public Function GetRndNotRepeat(ByVal NumMin As Integer, ByVal NumMax As Integer, ByVal n As Integer)
'编制:xsfhlzh
'功能:取NumMin到NumMax间的n个随机整数
'说明:取数标志数组是Byte,每一位表示NumMin到NumMax间某个数的状态
Dim arr() As Integer
If n > NumMax - NumMin + 1 Then
ReDim arr(0)
arr(0) = 0
Else
ReDim arr(n)
Dim b() As Byte
Dim m As Integer
m = Int((NumMax - NumMin) / 8)
ReDim b(m)
'取数标志
Dim x As Integer, y As Integer
Dim z As Byte
Randomize
arr(0) = 1
For i = 1 To n
Do
'找到x的位置,y表示x在数组的第几个字节,z表示x在该字节的第几位
x = Int(Rnd * (NumMax - NumMin + 1)) + NumMin
y = x - NumMin
z = 2 ^ (y Mod 8)
y = y \ 8
Loop While b(y) And z
b(y) = b(y) Or z
arr(i) = x
'找到未取的数,并放入数组,设置标志位
Next i
End If
GetRndNotRepeat = arr
End Function
Private Sub Command1_Click()
Dim strRed As String
Dim strBlue As String
Dim vRed As Variant
Dim vBlue As Variant
Dim intData(1 To 6) As Integer
Dim str1 As String
Dim n As Integer
Dim min As Integer
strRed = "02,03,04,07,08,09,12,13,14,17,18,19,22,23,24,27,28,29,32,33"
strBlue = "03,04,05,09,13,14,15"
vRed = Split(strRed, ",")
vBlue = Split(strBlue, ",")
List1.Clear
Text1.Text = ""
Text2.Text = ""
'以下代码将红球值写入LIST中,并随机选出6个存入intData()中
For i = 0 To UBound(vRed)
List1.AddItem vRed(i)
Next i
For i = 1 To 6
Randomize
n = Int(Rnd * List1.ListCount)
intData(i) = List1.List(n)
List1.RemoveItem (n)
Next i
'将intData()中的数据进行排序
For i = 1 To 6
For j = i + 1 To 6
If intData(i) > intData(j) Then
min = intData(j)
intData(j) = intData(i)
intData(i) = min
End If
Next j
Next i
'下面代码将选出的6个数进行格式化并显示在text1中
For i = 1 To 6
str1 = str1 & CStr(Format(intData(i), "00")) & " "
Next i
Text1.Text = str1
n = UBound(vBlue)
Randomize
n = Int(Rnd * UBound(vBlue))
str1 = ""
str1 = CStr(Format(vBlue(n), "00"))
Text2.Text = str1
End Sub
如要实现排序+随机,需分两行显示:
1、随机数据,假设在A1--F1,则在A1到F1输入公式:
=ROUND((RAND()*(33-1)+1),0)
2、排序,在A2输入公式:
=LARGE($A1:$F1,7-COLUMN()),点右下角出现的“+”按住左键往右拉到F2。
因为RAND()函数实现是的随机小数,不是随机整数,故偶尔会出现重复,出现上状况时,重新运算就行了,快捷键F9,会重算。
http://download.csdn.net/source/405513
也可以