截图:
/*** 随机选取红色球
*
* 获取1~33其中一个数
*
* 0 <= Math.random < 1
*/
private int randomOneRedValue() {
int randomValue = (int) (Math.random() * 33 + 1)
return randomValue
}
选取蓝色球号码方法:
/*** 随机选取蓝色球号码
*
* 获取1~16的数值
*
* @return
*/
private int randomOneBlueValue() {
int 或渣randomValue = (int) (Math.random() * 15 + 1)
return randomValue
}
测试:
public class Test1 {public static void main(String[] arg) {
Test1 localTest1 = new Test1()
// 双色球 :红色球号码 + 蓝色球号码
// 六个红色球和一个蓝色球号码
// 红色球号码从1~33中选择
// 蓝色球号码从1~16中选择
// 一等奖:七个号码相符(六个红色号码和一个蓝色球号码)(红色球号码顺序不限,下同)
// 二等奖:六个红色球号码相符散芦
// 三等奖:五个红色球号码,或者四个红色球号码和一个蓝色球号码相符;
// 四等奖:五个红色球号码,或者三个红色球冲团带号码和一个蓝色球号码相符;
// 五等奖:四个红色球号码,或者三个红色球号码和一个蓝色球号码相符;
// 六等奖:一个蓝色球号码相符(有误红色球号码相符均可)
// 例如:红色球号码 01 06 13 19 24 28 蓝色球号码 16
System.out.println("开始出奖")
// 定义双色球数组,大小为7
String[] values = new String[7]
for (int i = 0 i < 7 i++) {
if (i == 6) {
int blueValue = localTest1.randomOneBlueValue()
if (blueValue < 10) {
values[i] = "0" + blueValue
} else {
values[i] = String.valueOf(blueValue)
}
} else {
int redValue = localTest1.randomOneRedValue()
if (redValue < 10) {
values[i] = "0" + redValue
} else {
values[i] = String.valueOf(redValue)
}
}
}
System.out.println()
System.out.println("出奖结束")
System.out.println()
System.out.print("双色球开奖号码:")
// 打印双色球号码
for (String value : values) {
System.out.print(" " + value)
}
}
}
#include<stdlib.h>#include<stdio.h>
#include<弯码郑time.h>
const int MAX1=33
const int MAX2=16
void main()
{
int 模扰x[6]={0}
int y=0
int i,j,k,r
k=0
srand(time(0))
while(k<6)
{
r=rand()%MAX1+1
for(i=0i<ki++)
if(x[i]==r)
break
x[k++]=r
}
y=rand()%MAX2+1
for(i=0i<6i++)
printf("%d ",x[i])
printf(" %d"埋颂,y)
}
建立两个Command1和2Dim 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
已经运行过。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)