存入隨機且不重覆的資料
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then DoRandomize(25)
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then DoRandomize(50)
End Sub
Private Sub DoRandomize(ByRef tmpIndex As Integer)
'清空 ListBox1
ListBox1.Items.Clear()
Dim sw As New Stopwatch()
sw.Reset()
sw.Start()
For x As Integer = 1 To tmpIndex
'Randomize 函式(Number) 與 Rnd 函式(Number)
'Randomize 省略了 Number,則會使用系統計時器傳回的值做為新的種子值。
'Rnd 如果沒有使用 Randomize,則函式會使用第一次呼叫時所使用的值做為種子,
'之後將會使用前一次所產生的值做為種子值。也就是對於任何特定的初始種子,
'都會產生相同的數字序列。
Randomize()
'亂數總數一定要大於欲選取的隨機數量
Dim tmpVal As Integer = Int(tmpIndex * 2 * Rnd() + 1)
If CheckBox1.Checked = True Then Me.Text = "現在亂數--> " & tmpVal
'ListBox...FindString 方法 (String)
'尋找 ListBox 中第一個以指定字串為開頭的項目。
'命名空間:System.Windows.Forms()
'組件:System.Windows.Forms (在 System.Windows.Forms.dll 中)
'FindString 方法在 ListBox 中搜尋字串的第一個執行個體,
'如果找不到符合搜尋字串的項目,FindString 將傳回 -1 值。
Dim index As Integer = ListBox1.FindString(tmpVal)
If index <> -1 Then
If CheckBox1.Checked = True Then
ListBox1.SetSelected(index, True)
Me.Text = "現在亂數--> " & tmpVal & "重覆!!"
End If
Else
ListBox1.Items.Add(tmpVal)
End If
If CheckBox1.Checked = True Then
Threading.Thread.Sleep(100)
Application.DoEvents()
End If
'如果 ListBox 筆數不等於隨機數量,則繼續跑迴圈
If tmpIndex <> ListBox1.Items.Count Then x = ListBox1.Items.Count
Next
sw.Stop()
Me.Text = "RunTime " & String.Format("{0:#,0.00000;(#,0.00000);-}", sw.Elapsed.TotalMilliseconds / 1000) & "s"
RadioButton1.Checked = False
End Sub
訂閱:
張貼留言 (Atom)
Hi there! I simply would like to give a huge thumbs up for the great information
回覆刪除you will have right here on this post. I will probably be coming
again to your blog for more soon.
Feel free to surf to my web-site: japan highways
Howdy! I simply want to give a huge thumbs
回覆刪除up for the good information you’ve got right here on this
post. I will be coming back to your blog for extra soon.
Here is my homepage; all music songs from my fair lady
Hey! I just want to give a huge thumbs up for the nice information you may have
回覆刪除here on this post. I will probably be coming back to your weblog for extra soon.
Also visit my homepage :: slide show
Hi there! I simply would like to give an enormous thumbs up for the nice info you’ve here on this
回覆刪除post. I might be coming back to your blog for more soon.
My blog best travel accessories for international