[.NET] 產生亂數 ... 我這樣寫哪裡有問題

看板Visual_Basic作者 (Yes)時間18年前 (2006/12/26 14:43), 編輯推噓2(202)
留言4則, 3人參與, 最新討論串1/5 (看更多)
各位大大...小弟初學VB.net 想要產生6個亂數在1-49之間 很直觀就這樣寫 Dim a, b, c, d, h, f As Integer Do Randomize() a = Int(Rnd() * 49 + 1) b = Int(Rnd() * 49 + 1) c = Int(Rnd() * 49 + 1) d = Int(Rnd() * 49 + 1) h = Int(Rnd() * 49 + 1) f = Int(Rnd() * 49 + 1) Loop Until a <> b <> c <> d <> h <> f Label1.Text = a Label2.Text = b Label3.Text = c Label4.Text = d Label5.Text = h Label6.Text = f 印出之後發現有時候會有重複的數字 不知道是哪邊有問題呢..? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.211.65.41

12/26 14:52, , 1F
你這樣寫只能說A不會跟B相同C是可以跟A一樣的~
12/26 14:52, 1F

12/26 14:54, , 2F
用IF作判斷式吧
12/26 14:54, 2F

12/26 15:02, , 3F
soga.....感恩 ^^
12/26 15:02, 3F

12/27 16:05, , 4F
我比較好奇跑出來的數字有沒有中 XD
12/27 16:05, 4F
文章代碼(AID): #15aCI7mU (Visual_Basic)
文章代碼(AID): #15aCI7mU (Visual_Basic)