我有一个特定的数组整数
Dim ArrayWinRandomNumber(0 To 5) As Integer
和另一个接受它的功能
Private Sub repetido()
For x = 0 To 5
Randomize()
Dim RandomNumber As Integer
RandomNumber = CInt(Int((49 * Rnd()) + 1))
For y = 0 To 5
If RandomNumber = ArrayWinRandomNumber(y) Then
repetido()
End If
Next
ArrayWinRandomNumber(x) = RandomNumber
Next x
ordenar()
End Sub
问题是,他第一次打电话重复,它工作正常,但如果你第二次回电话。我退回了IndexOutOfRangeException
答案 0 :(得分:1)
你应该做这样的事情(你使用像vb6这样的vb.net)
Imports System.Linq
. . . . . . . . . . .
Dim r as new Random()
Dim items() as Integer = Enumerable.Range(1, 5).Select(Function(i) r.Next()).ToArray()
For Each i as Integer in items
console.WriteLine("Item val: " & i)
Next
它会随时给你一组随机数