用VB编写双色球程序,要求是以指定数字为尾的数字中随机选择该怎么编写程序

要用VB编程序,众所周知,双色球是随机输出一组双色球号码,先从1到33数字的33个红色球任选6个,再从数字为1到16的16个蓝色球任选1个组成一组开奖号码。
但我想要的程序功能略有不同,红球里面我只想从个位含有2,3,4,7,8,9尾的数字里随机出6个,比如从02,03,04,07,08,09,12,13,14,17,18,19,22,23,24,27,28,29,32,33中随机选6个,篮球也是一样,从16个数字里选择所有含有3,4,5,9尾的数字里随机出1个,这样的程序该怎么用VB实现,急,在线等,答案满意,我会追加100.
附带一点说明,希望程序的界面是摇出的数字一个一个顺序出,这样比较有真实感,而不希望是点击命令按钮7个数字一下就全部显示出来了,我希望就像中福彩现场开奖出球顺序一样。先是红球6个一个一个出,然后最后出篮球数字。谢谢。^-^
邮箱r2008j@126.com

我说的“篮球也是一样,从16个数字里选择所有含有3,4,5,9尾的数字里随机出1个”也是指1到16的所有数字含有这些尾的数字,比如03,04,05,09,13,14,15"共7个,随机出一个
最新回答
谁人都相处来

2024-09-05 03:40:16

建立两个Command1和2
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.5
FillStyle = 0
FillColor = vbRed
Form1.Circle (500 + i * 500, 1000), 200, vbRed
CurrentX = 350 + i * 500
CurrentY = 840
Print Format(RedBalls(rarr(i)), "00")
Next i
t = Now
Do
DoEvents
Loop While DateDiff("s", t, Now) < 2
i = 7
FillStyle = 0
FillColor = vbBlue
Form1.Circle (500 + i * 500, 1000), 200, vbBlue
CurrentX = 350 + i * 500
CurrentY = 840
Print Format(BullBalls(barr(1)), "00")
End Sub

Private Sub Command2_Click()
End
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)
'Label1.Caption = ""
Command1.Caption = "开始"
Command2.Caption = "退出"
Form1.FontSize = 15
Form1.FontName = "Arial"
Form1.ForeColor = &HFFFFFF
End Sub

Public Function GetRndNotRepeat(ByVal NumMin As Integer, ByVal NumMax As Integer, ByVal n As Integer)
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 = 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
已经运行过。
﹋ˋ︸黑曼斑

2024-09-05 15:13:11

一个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
云终韵

2024-09-05 05:28:37

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
天空天然蓝

2024-09-05 07:58:18

如要实现排序+随机,需分两行显示:

1、随机数据,假设在A1--F1,则在A1到F1输入公式:

=ROUND((RAND()*(33-1)+1),0)

2、排序,在A2输入公式:

=LARGE($A1:$F1,7-COLUMN()),点右下角出现的“+”按住左键往右拉到F2。

因为RAND()函数实现是的随机小数,不是随机整数,故偶尔会出现重复,出现上状况时,重新运算就行了,快捷键F9,会重算。
谁愿意当小三

2024-09-05 10:03:18

一个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
也可以
伪装者

2024-09-05 04:37:32

世界上没有做不到的·只有想不到了·但我没有那本事·祝LZ的想法早日呈现·