作者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