作者ssaume (南极居乡民)
看板Visual_Basic
标题Re: [.NET] 乱数不重复判断
时间Tue Dec 13 23:19:56 2005
Dim RandomNo As Random = New Random
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim I, J As Integer
Dim w, x, y, z As Integer
Dim r, v, s As Integer
Dim out As String
w = N(1)
Do Until r <> 1
r = 0
x = N(2)
If w = x Then
r = 1
End If
Loop
Do Until v <> 1
v = 0
y = N(3)
If w = y Then
v = 1
End If
If w = x Then
v = 1
End If
Loop
Do Until s <> 1
s = 0
z = N(4)
If w = z Then
s = 1
End If
If x = z Then
s = 1
End If
If y = z Then
s = 1
End If
Loop
out = w & ";" & x & ";" & y & ";" & z
TextBox1.Text = out
End Sub
Function N(ByVal a As Integer) As Integer
Dim c = RandomNo.Next(1, 10)
Return c
End Function
End Class
以上程式码是我想了又想写出来的...
不过跑出来一直是 ???:0:0:0
第一个是都是1~9的乱数 不过後面三个就跑不出来了...
理想应该是4个都是乱数 且不重复...
大大们可以指正一下吗?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.59.229.133
1F:→ silentlich:把Until r <> 1 移到 Loop 後面试试看 12/13 23:39
2F:→ ssaume:喔喔~~~谢谢大大~~~ 终於解出来了... 12/14 13:32