vb随机数 1000 没次随机出现1个数,1000次内不出现重复的数
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/20 04:30:18
vb随机数 1000 没次随机出现1个数,1000次内不出现重复的数
vb随机数 1000 没次随机出现1个数,1000次内不出现重复的数
vb随机数 1000 没次随机出现1个数,1000次内不出现重复的数
代码改过了.:
Dim CurrentNumber As Integer
Dim arr() As Integer
Dim finish,ifget As Boolean
Function getRnd(i As Integer) As Integer '取1-i之间的随机数一个
Randomize
getRnd = Int(Rnd() * i + 1)
End Function
Function getAllRnd(Counter As Integer,jishu As Integer) As Integer() '取Counter个1-jishu之间的随机数
If (Counter > jishu) Then
MsgBox "数字个数不能大于基数"
Exit Function
End If
ReDim arr(Counter) As Integer
i = 0
Do While i < Counter
arr(i + 1) = getRnd(jishu)
found = False
For x = 1 To i
If arr(x) = arr(i + 1) Then
found = True
Exit For
End If
Next
If Not found Then
i = i + 1
End If
Loop
getAllRnd = arr
End Function
Sub test()
If finish Then
Exit Sub
End If
If Not ifget Then
arr = getAllRnd(10,10)
CurrentNumber = CurrentNumber + 1
Print arr(CurrentNumber)
ifget = True
Else
CurrentNumber = CurrentNumber + 1
Print arr(CurrentNumber)
If CurrentNumber = 10 Then
finish = True
End If
End If
End Sub
Private Sub Command1_Click()
Call test
End Sub