我正在尝试创建一个不重复的数字数组。优先顺序是从上到下,从左到右,我试图获得x到y的范围。但是不需要在范围内重复值
Dim arrayCarton(9, 3) As Integer
Private Sub generar_carton()
Randomize()
filas = 3
columnas = 9
Dim RandomNumber As Integer
For j = 0 To columnas - 1
For i = 0 To filas - 1
Dim label As Label = CType(Panel2.Controls("Carton" & i & j), Label)
If j = 0 Then
RandomNumber = CInt(Math.Floor(((9 * (j + 1)) - 1) * Rnd())) + 1
End If
If j < 8 And j > 0 Then
RandomNumber = CInt(Math.Floor(((j * 10 + 9) - j * 10) * Rnd())) + j * 10
End If
If j = 8 Then
RandomNumber = CInt(Math.Floor(((9 * 10) - j * 10) * Rnd())) + j * 10 + 1
End If
arrayCarton(j, i) = RandomNumber
label.Text = arrayCarton(j, i)
Next
Next
End Sub
可以看到一些数字被重复输出: