作者rosemary (原po比較老)
看板Visual_Basic
標題Re: [.NET]亂數不重複
時間Thu Oct 6 14:29:48 2005
※ 引述《HeyScng ( )》之銘言:
: 這是我的想法
: Dim A() As Integer = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
: Dim temp As Integer
: Dim i,j As Integer
: For i = 1 To i = 9
For i = 1 to 9
: j = Int(Rnd() * 9 + 1)
: temp = A(i) ////交換兩張牌
: A(i) = A(j)
: A(j) = temp
: Next
: Button1.Text = A(1)
...(中省略)
: Button9.Text = A(9)
Dim btn() As Button = {Button1, Button2, Button3, Button4, _
Button5, Button6, Button7, Button8, Button9}
For i = 0 To 8
btn(i).Text = A(i + 1)
Next
: 基本上的想法是先設初值number 1~9 並隨機交換這九個數字以達到亂數的目地
: 最後後傳回A(1)~A(9)則為亂數 可是總跑不出來
因為迴圈寫錯了 :)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 192.192.5.253
1F:推 HeyScng:卸卸你!! 218.170.114.20 10/06 23:08