求助:用批处理制作一个随机选号程序

求助:用批处理制作一个随机选号程序,第1张

下面是产生1到5之间的

随机数

,包含1,2,3,4,5;(不包含0哦)

::═════代═══码═══开═══始═════

@echo

off&title

选号程序&color

4a

mode

con:

cols=40

lines=5

set

/a

a=%Random%

%%5

if

%a%==0

set/a

a=5

echo

您的随机数值为:%a%&echo.&echo.

echo:请按任意键进行重新选号...

pause>nul

cls&call

%0

::═════代═══码═══结═══束═════

Const numb = 2000

Dim S(1 To numb) As String, C(1 To numb) As String 's()为号码源,c()为随机号码

Sub Main()

Dim k%, tmp%

k = 1

Do While k <= numb

Randomize '设置不重复随机取数

tmp = Int(Rnd() * 1999 + 1)

If S(tmp) <>"" Then

C(k) = S(tmp)

S(tmp) = ""

k = k + 1

End If

Loop

End Sub

因为c()为随机取数,每次可以取前10个数作为一次抽奖结果,直到抽奖完

建立两个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

已经运行过。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12106927.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-21
下一篇2023-05-21

发表评论

登录后才能评论

评论列表(0条)

    保存