Re: [.NET] 亂數不重複判斷

看板Visual_Basic作者 (南極居鄉民)時間20年前 (2005/12/13 23:18), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串2/2 (看更多)
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
把Until r <> 1 移到 Loop 後面試試看
12/13 23:39, 1F

12/14 13:32, , 2F
喔喔~~~謝謝大大~~~ 終於解出來了...
12/14 13:32, 2F
文章代碼(AID): #13dkOl39 (Visual_Basic)
文章代碼(AID): #13dkOl39 (Visual_Basic)