Re: [.NET] 亂數不重複判斷
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
→
12/13 23:39, , 1F
12/13 23:39, 1F
→
12/14 13:32, , 2F
12/14 13:32, 2F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
Visual_Basic 近期熱門文章
PTT數位生活區 即時熱門文章