我试图将5个变量随机化为1到5之间的整数,但要使每个变量不能相等。我现在可以将这些数字随机化,但有些最终是相同的。当我添加随机化数字序列的代码直到它们不相等时,它就会结束冻结。感谢任何帮助。谢谢。
这是我的代码:
Dim rndnum As Random
Dim qcombo As Boolean = False
Dim q1 As Integer
Dim q2 As Integer
Dim q3 As Integer
Dim q4 As Integer
Dim q5 As Integer
rndnum = New Random
Do
q1 = rndnum.Next(1, 5)
q2 = rndnum.Next(1, 5)
q3 = rndnum.Next(1, 5)
q4 = rndnum.Next(1, 5)
q5 = rndnum.Next(1, 5)
If q1 = q2 Or q1 = q3 Or q1 = q4 Or q1 = q5 Or q2 = q3 Or q2 = q4 Or q2 = q5 Or q3 = q4 Or q3 = q5 Or q4 = q5 Then
qcombo = False
Else
qcombo = True
Loop Until qcombo = True